django Admin

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

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--> ( admin.autodiscover() ) -- > ( INSTALL APPS(each app) ) -->

(app included) > to execute its code

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

2,Treatment of

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

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

#The registration module

The (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

In this way, the overall effect is as follows:

Two, authority

Django extends User to write their certification background

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

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