Fullstack Development - Module 3
Fullstack Development - Module 3
6th SEMESTER – B. E
Academic Year: 2023 – 2024 (Even)
Fullstack
Development
Presenter: Mrs. Shilpashree S
Assistant Professor, Dept. of CSE,
SJB Institute of Technology
Django Admin Interfaces
One of Django’s killer features is its robust built-in admin interface that provides a visual
way to interact with data.
This is a Web-based interface, limited to trusted site administrators, that enables the
adding, editing and deletion of site content.
It reads metadata from your models to provide a quick, model-centric interface where
trusted users can manage content on your site.
6.1 Activating the Admin Interface
django.contrib.auth
django.contrib.contenttypes
django.contrib.messages
django.contrib.sessions
urlpatterns = [
path('admin/', admin.site.urls),
]
8. Create a superuser account (a user who has all permissions). This is useful if you need to
create an initial superuser account or if you need to programmatically generate superuser
accounts for your site(s).
SuperUser Creation
python3 manage.py createsuperuser
Username: Provide Username
Email address: Provide Email Address
Password: Provide Password
Password (again): Type the password again
Superuser created successfully.
9. That’s it. Now run python manage.py runserver to start the development server.
The first thing you’ll see is a login screen. You’ll use the username and password you set up when you
added your superuser.
Each object registered in admin.py shows up on the main index page.
When you register a model in the Django administration site, you get a user-friendly
interface generated by introspecting your models that allows you to list, edit, create,
and delete objects in a simple way.
Admin Interface adds the data to the database with ease.
Django uses different form widgets for each type of field. Even complex fields, such as the DateTimeField,
are displayed with an easy interface, such as a JavaScript date picker.
Clicking the "+" button opens a popup form, allows to create a new publisher on the fly without pre-
populating any data.
Observe Recent Actions originated from “django_admin_log” (db.sqlite3)
Admin interface also handles input validation for you
When you delete an existing object, the admin interface asks you to confirm the delete action to avoid
costly mistakes.
Deletions also cascade; the deletion confirmation page shows you all the related objects that will be deleted as well.
6.2.1 Users, Groups, and Permissions
● Since we’re logged in as a superuser, we have access to create, edit, and delete any
object.
● However, the admin interface has a user permissions system that we can use to give
other users access only to the portions of the interface that they need.
● We can edit these users and permissions through the admin interface just like any
other object. The link to the User and Group models is there on the admin index
along with all the objects we’ve defined.
● User objects have the standard username, password, e-mail, and real name fields you
might expect, along with a set of fields that define what the user is allowed to do in
the admin interface.
6.2.1 Users, Groups, and Permissions - Contd..
Each object editable through the admin interface has three permissions: a create permission, an edit permission,
and a delete permission. Assigning permissions to a user grants the user access to do what is described by those
permissions.
6.2.1 Users, Groups, and Permissions - Contd..
Note
Access to edit users and permissions is also controlled by this permission system. If you
give someone permission to edit users, she will be able to edit her own permissions, which
might not be what you want!
You can also assign users to groups. A group is simply a set of permissions to apply to all
members of that group. Groups are useful for granting identical permissions to large
number of users.
6.3 Customizing the Admin Interface
We can customize the way the admin interface looks and behaves in a number of ways. we can easily add some
display, searching, and filtering functions to this interface. Change the Admin declaration as follows:
class Book(models.Model):
title = models.CharField(maxlength=100)
authors = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher)
publication_date = models.DateField()
class Admin:
list_display = ('title', 'publisher', 'publication_date')
list_filter = ('publisher', 'publication_date')
ordering = ('-publication_date',)
search_fields = ('title',)
6.4 Customizing the Admin Interface Look and Feel
If you want to customize the default admin site, you can override it.
6.4 Customizing the Admin Interface’s Look and Feel - Contd..
Come up with case studies on when and why admin interfaces are helpful.