Open In App
Related Articles

Python | Django Admin Interface

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

In this article, we delve into the capabilities and advantages of the Django Admin Interface, exploring how its customizable features and streamlined workflows empower developers to effortlessly administer their projects, from data management to user interactions.

Prerequisites: django-introduction-and-installation | django-introduction-set-2-creating-a-project

Django Admin Interface

When you start a project with Django it also provides a default admin interface that can be used to perform create, read, update, and delete operations on the model directly. It reads a set of data that explains and gives information about data from the model, to provide an instant interface where the user can adjust the contents of the application. This is an in-built module designed to execute admin-related work for the user.

Creating a Superuser in Django Project

The Superuser is the one who can access the Django administration panel and can perform CURD operation on the created models which are shown in the admin panel. The admin app(django.contrib.admin) is enabled by default and already added to the INSTALLED_APPS list present in the settings.py file.

installed_packs

To access this admin interface on browser write ‘/admin/’ at ‘localhost:8000/admin/’ and it shows the output as given below:

Note: we are assuming that you have deployed your project on local server.

login

It prompts for login details, if no login id is created before, then a new superuser can be created by using the command given below:

python manage.py createsuperuser
https://media.geeksforgeeks.org/wp-content/uploads/Screenshot-529.png

Now, access the admin login page after starting the Development Server which can be done by using the command given below.

python manage.py runserver
runserver

Enter username and password, then hit login .

login

After logging in successfully, it shows the interface as shown below: .

Django Admin Interface

This is what is called a Django Admin Dashboard where one can add, delete and update data belonging to any registered model.

Reset Django Admin Password

In Django we can reset django admin password but for this this must make sure you already created a superuser already for which we uses `createsuperuser`command . This command allows you to create a new superuser account or update an existing one if you already have one, and after creating the superuser as show in the above article then we can use the `changepassword` command provided with name of the super user with it and it will change the superuserpassword this will reset the django admin password.

Before writing the command make sure that current directory must have manage.py file within it and If not Open the terminal and cd (change directory) into the project folder (the directory with the manage.py file).

Then run the command:

python manage.py changepassword <username>

Replace <username> with the username of the user for whom you want to change the password.

Here’s an example of how you would use the changepassword command in my case the superuser is Abhishek_Shakya so cammad would be like

python manage.py changepassword Abhishek_Shakya
Untitled-1
Changepassword of the superuser

and by this we can reset or update the superuser password

Register Model in Django Admin

After starting your project in django and creating or resetting your django superuser you can now access the django administrator and through django admin panel you can perform CRUD operations on your models but the model you created in your app only shows in the admin panel when you register them in your `admin.py` of the app you created.

after stating the project create an app

python manage.py createapp myapp

Now in the myapp folder we have the file models.py in which we create our model and after creating those model we need to register them in the admin.py file of the myapp folder after that we makemigrations of the model created.

Screenshot-(13)-(3)
register model in django-admin

and the after model creation you have to register the model in django by regestering them into admin.py file of `myapp` folder

first import your model at the top of the admin.py file if the model you are importing is in the same file you can import by

from .models import <model.name>

In this case the model is Faclity_details, so

from .models import Faclity_details

Now we have to register the model in the admin.py file so that it can we visible on the admin panel

admin.site.register<Model.name>

In this case the model is Faclity_details,so

admin.site.register(Faclity_details)
Untitled-3
Register model in admin
python manage.py makemigrations

after that migrate all the migrations

pyhton manage.py migrate

Now the admin page will have the model Faculty_details but make sure the server is up and running.

Django Admin Interface

Now you are all set to go.



Last Updated : 21 Aug, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads