标签:creates 点击 本地化 注册 models tin 管理 create 服务器
python manage.py runserver ip:port
python manage.py runserver 8080
python manage.py createsuperuser,按提示输入用户名、邮箱、密码
LANGUAGE_CODE = ‘zh-Hans‘
TIME_ZONE = ‘Asia/Shanghai‘
from django.contrib import admin
from models import BookInfo
admin.site.register(BookInfo)
class QuestionAdmin(admin.ModelAdmin):
...
admin.site.register(Question, QuestionAdmin)
list_display = [‘pk‘, ‘btitle‘, ‘bpub_date‘]
list_filter = [‘btitle‘]
search_fields = [‘btitle‘]
list_per_page = 10
fields = [‘bpub_date‘, ‘btitle‘]
fieldsets = [
(‘basic‘,{‘fields‘: [‘btitle‘]}),
(‘more‘, {‘fields‘: [‘bpub_date‘]}),
]
对于HeroInfo模型类,有两种注册方式
按照BookInfor的注册方式完成HeroInfo的注册
from django.contrib import admin
from models import BookInfo,HeroInfo
class HeroInfoInline(admin.StackedInline):
model = HeroInfo
extra = 2
class BookInfoAdmin(admin.ModelAdmin):
inlines = [HeroInfoInline]
admin.site.register(BookInfo, BookInfoAdmin)
class HeroInfoInline(admin.TabularInline)
def gender(self):
if self.hgender:
return ‘男‘
else:
return ‘女‘
gender.short_description = ‘性别‘
class HeroInfoAdmin(admin.ModelAdmin):
list_display = [‘id‘, ‘hname‘, ‘gender‘, ‘hcontent‘]
标签:creates 点击 本地化 注册 models tin 管理 create 服务器
原文地址:https://www.cnblogs.com/joshuazc/p/9533084.html