Admin is a Django-brought database management tool, an app
In admin.py, you can customize the class to make the Admin Database Administration page show the information you want to see
models.py
fromDjango.dbImportModels#Create your models here.classBook (models. Model): Title= Models. Charfield (max_length=32) Price= Models. Decimalfield (max_digits=6, decimal_places=2) Pub_date=models. Datefield () Authors= Models. Manytomanyfield (to="Author") def __str__(self):returnSelf.titleclassAuthor (models. Model): Name= Models. Charfield (max_length=32) def __str__(self):returnSelf.name
View Code
admin.py
fromDjango.contribImportAdmin fromApp01.modelsImport*#Register your models here.classbookconfig (admin. Modeladmin):"""Custom classes enable you to see the information you want to see on the Admin Database Administration page"""List_display= ["title"," Price","pub_date"]#Many-to-many fields cannot be used hereList_display_links = ["title"]#after setting the linked field settings, click the field to go to the edit pageList_filter = ["pub_date"]#record a query with the field you set as a filterList_editable = [" Price"]#set editable fields, note: If you set a field in List_display_links, you can no longer set it here .Search_fields = ["title"," Price"]#Set the search field (Fuzzy query: Enter a keyword to query)Date_hierarchy ="pub_date" #Filter Date #action: Batch operation record defFunc (self, request, Queryset):#Request: Requested Queryset: Selected data that you want to manipulate Print(self, request, Queryset)#to manipulate a selected record:Queryset.update (pub_date="2012-1-1")#change the publication date of the selected record to January 1, 2012Func.short_description ="publication date changed to January 1, 2012"Actions=[func,] fields= ["title"," Price","pub_date","authors"]#fields displayed on the page where the record is added #exclude = ["Pub_date"] # field not displayed on the page where the record is added, contrary to fieldsOrdering= ["ID"]#Sort Descending by ID in ascending order ["-id"]admin.site.register (book, bookconfig)#Source: Register (self, model_or_iterable, Admin_class=none, **options)#Model_or_iterable=book, Admin_class=bookconfigPrint(admin.site._registry) admin.site.register (Author)
View Code
Admin--django comes with database management tools