Django Admin is a backend user interface for web application superuser and staff users. You can register your, models in the admin site and can control create, view, change and delete activities in models. A superuser can be created first with createsuperuser command and then the other users can be created from the Admin interface.
To create your first user as superuser run:
python manage.py createsuperuser
It will then ask to input the below fields and confirm Superuser was created successfully.
Username :
Email address:
Password:
Password (again):
You may visit the admin page with the below URL (if the development server is running):
You can then use the aforementioned login credentials on the Django Administration page. Other Users and authentication Groups can be created with an Admin interface.
To register models with the admin interface simply add the below statement in the admin.py module. Here Blog is an example of a Model name.
from django.contrib import admin
from .models import Blog
admin.site.register(Blog)
Django admin can offer a dashboard with many options to view and manage model data. Below are some admin options and their implications.
list_display = ['field1', 'field2', ...]
list_filter = ['field1', 'field2', ...]
fields = ['field1', 'field2', ('field3', 'field4'), ...]
fieldsets = (
(None, {
'fields': ('field1', 'field2', ...)
}),
('Availability', {
'fields': ('field1', 'field2', ...)
}),
)
list_editable = ['field1','field2',...]
search_fields = ['field1','field2',...]
exclude = ['field1','field2',...]
ordering = ('field1', ...)
list_per_page = 25
radio_fields = {"field_name": admin.HORIZONTAL, ...}