Django admin site

Register the model that can be operated through the background in admin.py

from django.contrib import admin 

# Register your models here.
from user.models import BookInfo, HeroInfo


#
# Subclass TabularInline: embedded in the form of a table.
class HeroInfoTabular (admin.TabularInline):
# The name of the associated model
model = HeroInfo

# Number of edits
extra = 1


#
# Subclass TabularInline: Embedded in the form of a table.
class HeroInfoStack (admin.StackedInline):
# The name of the associated model
model = HeroInfo

# The number of edits
extra = 1


# Subclass StackedInline: Embedded in the form of a block.

# Customize the Admin manager object Manager
class BookInfoAdmin (admin.ModelAdmin):
# 列 操作

# 1. Which fields to display
# See the source code is to call the __str__ method so customize the date_time method in the model class
list_display = ['id', 'btitle', 'bpub_date', 'date_time']

# 2. The number of pages displayed per page 100
list_per_page = 2

# 3. Location of operation options
actions_on_top = True
actions_on_bottom = True

# 5. Search box
search_fields = ['btitle']

# 6. Custom column name method column
# 7. Related objects

# Modify the style of the editing page!
#
1.Display fields # fields = ['btitle', 'bpub_date']
# 2. Group display
fieldsets = (
('Must pass', {'fields': ['btitle', 'bpub_date', 'image']} ),
('Optional', {
'fields': [' bread ',' bcomment '],
# folding style
'




# 3. Associated objects-fill in the corresponding heroes in the block and table fill in the book information
inlines = [HeroInfoTabular]
# inlines = [HeroInfoStack]

pass


# multiple inheritance
admin.site.register (BookInfo, BookInfoAdmin)


# [email protected]
( HeroInfo)
class HeroInfoAdmin (admin.ModelAdmin):
list_display = ['id', 'hname', 'hbook', 'read']
# 4. Right side filter
list_filter = ['hgender']

pass


# Site homepage setting
admin. site.site_header = 'My Bookstore'
admin.site.site_title = 'My Bookstore MIS'
admin.site.index_title = 'Welcome'







Guess you like

Origin www.cnblogs.com/ls1997/p/12734777.html