django admin registered source acquaintance

 

 

 

When the registry in the app to use the method:

admin.site.register(models.Book)
django admin use
     1 . Register your application in the model table
    
     2 .Admin url law 
        HTTP: //127.0.0.1:8000/admin/app01/book/               Book Table View 
        HTTP: //127.0.0.1:8000/ admin / app01 / book / add /           add book tables 
        HTTP: //127.0.0.1:8000/admin/app01/book/3/change/       book a table editor 
        HTTP: //127.0.0.1:8000/admin/app01/ Book / 3 the delete / /       Book table delete pages 
        
        HTTP: //127.0.0.1:8000/admin/app01/publish/               View publish tables 
        HTTP: //127.0.0.1:8000/admin/app01/publish/add/           publish table add 
        http://127.0.0.1:8000/admin/app01/publish/3/change/       editors publish tables 
        HTTP: //127.0.0.1:8000/admin/app01/publish/3/delete/       delete pages publish table 
    
        PS:
             1 .admin will give each registered url generate CRUD four 
        
        
        of the five key parameters of function 
            list_display control display fields be careful not to put many-field 
    
    concept of class configuration 
    
    admin boot source 
        django will be followed by the implementation of each application at startup admin.py the file 
        from django.utils.module_loading Import autodiscover_modules 
        autodiscover_modules ( ' ADMIN ' ) 
        
    
    source singleton 
    
    registered source 
    
    class ModelAdmin (BaseModelAdmin): 
        ... 
        # configuration class
        
        
    class AdminSite(object):
        def __init__(self, name='admin'):
            self._registry = {}  # model_class class -> admin_class instance
        def register(self, model, 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.

            Registered already IS A Model IF, the this by Will The raise AlreadyRegistered. 

            IF IS A Model abstract, the this by Will The raise ImproperlyConfigured. 
            "" " 
            IF  not admin_class: 
                admin_class = ModelAdmin
             # Instantiate at The ADMIN class to the Save in at The Registry 
            self._registry [Model] = admin_class (model) 
    
    Site = AdminSite () 
        
    admin.py registration statement 
    
    admin.site.register (models.Publish)   # model table only and is registered in the parameter table model object instantiated generated 
    # as a key-value pair stored _registry into the field site object
    

 

Guess you like

Origin www.cnblogs.com/1624413646hxy/p/11279422.html