How to Display and Manage Module in Django Administration Panel

Posted on

In Django web-based framework application, there is a Django Administration Panel exist. In this context, it is the web-based page powered by a Django web-based framework where usually can be accessed by accessing the URL : http://localhost:8000/admin.

The above URL can be executed in the web browser after the following command is executed :

python manage.py runserver

The execution of the above command can be shown below :

user@hostname:~/myapp$ python manage.py runserver 
Performing system checks...

System check identified no issues (0 silenced).
January 13, 2018 - 03:29:39
Django version 1.9.4, using settings 'myapp.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Basically, the page which can be accessed after running the above command, it is shown as follows :

How to Display and Manage Module in Django Administration Panel
How to Display and Manage Module in Django Administration Panel

 

But if the main goal is having a module or application created inside the application powered by a Django web-based framework to be presented and displayed in the Django Administration Panel as shown below. Try to compare the image above with the image shown down below :

How to Display and Manage Module in Django Administration Panel
How to Display and Manage Module in Django Administration Panel

 

As shown in the above image, there is an additional display in the Django Administration Panel which is shown the name of the project and another two lines of additional module or application listed. Those application or module can be managed from the Django Administration Panel. There is a link with the label of ‘Add’ for adding a record and another link wit the label of ‘Change’ for editing the record. Off course, the record mentioned is the record which is associated with each of the application or module where basically it is represented with specific table for each of the application or module.

So, what does it need to take to be able to do that ?, in order to do that, just edit a file named ‘admin.py’ for achieving that purpose :

from django.contrib import admin
from course.models import Subject, Student

# Register your models here.

Several lines which is going to be added in order to display the link for managing application or node is shown as below :

class ModuleOneAdmin(admin.ModelAdmin):
list_display = ('name','number_credits')

admin.site.register(ModuleOne, ModuleOneAdmin)

class ModuleTwoAdmin(admin.ModelAdmin):
list_display = ('name','number_credits')

admin.site.register(ModuleTwo, ModuleTwoAdmin)

The above lines are for adding modules named ‘ModuleOne’ and ‘ModuleTwo’.

Leave a Reply