django-adminGetting started with django-admin


Django Admin is the CRUD interface of Django web framework. It is mostly automatically generated but can be widely customize. However, you must keep in mind that it is designed for trusted users only and has its limits. In any case, you must never give admin access to untrusted users.

Django Admin provides a high level of customization, but be careful of not falling too much customization details. If you do so, it's probably time to create you own custom interface without Django Admin at all.



VersionRelease Date

Setup Django Admin

Everything you need to get started with Django admin is already setup in Django's default project layout. This includes:


# `django.contrib.admin` and its dependancies.


        'OPTIONS': {
            'context_processors': [

Be careful about that is slightly different in Django >= 1.9 than in older versions.

from django.conf.urls import url
from django.contrib import admin

urlpatterns = [
from django.conf.urls import url, include
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', include(,

Version with include will still work in Django 1.9 but is deprecated and will be removed in the future.

If not already done, you must apply the base migrations:

$ python migrate

To access the admin, you also have to create a superuser with:

$ python createsuperuser

Once this is done, you can run your server:

$ python runserver

And visit the admin page at

Add a Model to Admin pages

When you created your own Models in a app, they still need to be registered in order to become available in the admin pages.

This is done in the admin submodule. If your app was created using startapp , an file should already lay in you app module. Otherwise create it.

from django.contrib import admin
from myproject.myapp.models import MyModel

All options are defined on the ModelAdmin subclass. some options:

class MyCustomAdmin(admin.ModelAdmin):
    list_display = ('name','age','email')  # fields to display in the listing
    empty_value_display = '-empty-'        # display value when empty 
    list_filter = ('name', 'company')      # enable results filtering
    list_per_page = 25                     # number of items per page 
    ordering = ['-pub_date', 'name']       # Default results ordering

# and register it, MyCustomAdmin)

A more concise way to register a model is to use the admin.register decorator:

class MyCustomAdmin(admin.ModelAdmin)

Customize django User Admin Model

from django.contrib.auth.models import User    
class UserAdmin(admin.ModelAdmin):
    list_display = ('email', 'first_name', 'last_name')
    list_filter = ('is_staff', 'is_superuser'), UserAdmin)

We need to unregister before register custom UserAdmin because in django User Model Admin already registered, So we need to firstly unregister User Model in our then we can register User Model with custom ModelAdmin

Remove a Model from Admin pages

Django Admin comes with some Models registerd by default. There a some occasions where you might want to remove a Model from the admin pages.

This is done in the admin submodule. If your app wass created using startapp , the file should already lay in your app module. Otherwise create it.

from django.contrib import admin
from django.contrib.auth.models import User