admin use and configuration parameters

admin use 
        to create the super user 
        registration table model in admin.py 
            admin.site.register (models.author) 
        Django comes with two default registration table 
        
    
    admin url generate a custom model law 
        HTTP: //127.0.0.1:8000/ admin / app01 / book /   book view 
        HTTP: //127.0.0.1:8000/admin/app01/book/1/change/   books editor 
        HTTP: //127.0.0.1:8000/admin/app01/book/1/ delete /   book delete 
        http: //127.0.0.1:8000/admin/app01/book/add/   add books of 
        
        speculation: 
        http: //127.0.0.1:8000/admin/app01/publish/   Press to view 
        http: //127.0.0.1:8000/admin/app01/publish/1/change/    Press editor
        HTTP://127.0.0.1:8000/admin/app01/publish/1/delete/   Press delete 
        HTTP: //127.0.0.1:8000/admin/app01/publish/add/   Add publishers 
        
        truth: 
        HTTP: // 127.0.0.1:8000/admin/app01/publish/ 
        HTTP: //127.0.0.1:8000/admin/app01/publish/1/change/ 
        HTTP: //127.0.0.1:8000/admin/app01/publish/1/ the Delete / 
        HTTP: //127.0.0.1:8000/admin/app01/publish/add/ 
    
    law: admin will give a registered model table at least four CRUD generation !!! url 
    
    
    ADMIN parameter configuration 
            # configure class admin Book a table in .py 
        class BookConfig (admin.ModelAdmin): 
            list_display = [ ' title ','price','publish','publishDate']
            list_display_links = ['title','price','publish']
            search_fields = ['title','price']
            list_filter = ['publish','authors'defActions function#]

            
            patch_init (Self, Request, QuerySet): 
                queryset.update (. price = 666 ) 

            patch_init.short_description = ' price-volume initialization ' 
            Actions = [patch_init] 

        
        list_display: 
            field specifies the data show 
            attention-many fields can not be on the list list_display display 
        list_display_links: 
            Specifies the field jump (jump to a field where data of the current edit page) 
        search_fields 
            search_fields = [ ' title ' , ' price ' ] 
            input box 1, contains a title is searched, or price data 1 comprising
                 1Render the search box on the page
                 2. supported between the condition and the condition " or " query 
        list_filter
             1 . It is not used to screen the general field, which is used to help you filter the foreign key field !!!
             2. Support query combination, as long as the options are lit " and " relation = name ' XX ' &. price = ' XXX ' 
        Actions 
            batch process data 
                # define a batch processing function 
                DEF patch_init (Self, Request, QuerySet): 
                    queryset.update (. price = 666)      # ---> queryset through the operation of the data object 
                # to write the function name is not capitalize the first letter of the function name 
                patch_init.short_description = 'Price batch initialization "   # ---> then all objects, this step is a function to add a property 
                # disposed in the configuration class 
                actions = [patch_init]

 

Guess you like

Origin www.cnblogs.com/Hale-wang/p/12030638.html