The template files that are used for admin page are found in git hub, under the following directory structure
django/django/contrib/admin/templates/admin/
The template files to be modifyed are placed under templates/admin from the top level directory in your project folder with the same correxponding name
Example
To modify the title and headings, modify base_site.html
{% extends "admin/base.html" %}
<!-- Modify title here -->
{% block title %} Admin - Rental Registration {% endblock %}
{% block branding %}
<!-- modify heading here -->
<h1 id="site-name"><a href="{% url 'admin:index' %}">Video Rental</a></h1>
{% endblock %}
{% block nav-global %}{% endblock %}
To do this, we create a new class in admin.py and register this class along with the model
The name of this class should be name of model followed by 'Admin' and inherit from admin.ModelAdmin
models.py
# Create your models here.
class Movie(models.Model):
title = models.CharField(max_length=256)
length = models.PositiveIntegerField()
release_year = models.PositiveIntegerField()
#Without this, the name of data in the table will be 'movie object'
def __str__(self):
return self.title
In admin.py
#to reorder the fields in the detail view of Movie object in admin interface
# The name of this class should be name of model followed by 'Admin'
class MovieAdmin(admin.ModelAdmin):
fields = ['release_year','title']
#Register this class along with your original model
admin.site.register(models.Movie,MovieAdmin)
To do this we add a variable search_fields in ModelAdmin class
class MovieAdmin(admin.ModelAdmin):
fields = ['release_year','title']
#Displays a search box and helps searching my movie title or length
search_fields = ['title','length']
In the ModelAdmin class
#Adding filters
# Not all fields can be appropriate for filters
#used for only categorical fields
list_filter = ['release_year']
In ModelAdmin class
#Displays additional fields in the list view page of the model
list_display = ['title','release_year','length']
In ModelAdmin class
#List of fields that are allowed to be editable in list view of the model
#NOTE : This set should be a subset of list_display
list_editable = ['length']