django Admin

A, Django site management

See Django book

Here the focus of listed the following knowledge:

(1),The working principle of admin:

1,Pre loading:

Project execution settings-->

urls.py ( admin.autodiscover() ) -- >

settings.py ( INSTALL APPS(each app) ) -->

(app included) admin.py >

Admin.py to execute its code

Django.contrib.auth contains its admin.py, corresponding to User,Group.

2,Treatment of admin.py

If the presence of admin.py in the project app will load the code.

The introduction of from to django.contrib import admin, at the same time through the admin.site.register () registered the corresponding app module.

#admin.py
#coding=utf-8
from django.contrib import admin
from admin_test.models import Person

#The registration module
admin.site.register(Person)

The admin.site.register (analysis):

def register(self, model_or_iterable, admin_class=None, **options):
        """
       Registers the given model(s) with the given admin class.
       The model(s) should be Model classes, not instances.
       If an admin class isn't given, it will use ModelAdmin (the default admin options). 
       If keyword arguments are given -- e.g., list_display -- they'll be applied as options to the admin class.
       If a model is already registered, this will raise AlreadyRegistered.
        """

The analysis and understanding of the above, you can customize the management tools.:

The custom management tool:

We created a new class of AuthorAdmin, which is derived from a subclass of django.contrib.admin.ModelAdmin, preserved a custom configuration class, for management tool.

class AuthorAdmin(admin.ModelAdmin):
    list_display=('name','age','sex')   #List display
    search_fields=('name',)             #Search
    list_filter = ('type',)             #Filter
    date_hierarchy = 'birth'            #Date field level classification. 
    ordering = ('-birth','age')         #The date of birth in descending order, the grade of ascending
    fields = ('name','sex','age','birth','type')    #Custom edit form, which fields are displayed in the edit form, display attribute
           
admin.site.register(Person,AuthorAdmin)

In this way, the overall effect is as follows:


Two, authority

Django extends User to write their certification background

Posted by Emma at November 13, 2013 - 12:06 PM