# Writing your first Django app, part 2
创建admin用户
D:\desktop\todoList\Django\mDjango\demoSite>python manage.py createsuperuser
然后输入密码
进入admin网址
D:\desktop\todoList\Django\mDjango\demoSite>python manage.py runserver 8080
改变字段顺序
-
fileds 改变字段的顺序
-
fieldset 给字段分组
-
classes 折叠字段
-
serch_fields 添加搜索框
-
list_display 需要显示的字段
from django.contrib import admin
from DemoAppPoll.models import Choice,Question
class ChoiceInline(admin.TabularInline):
model = Choice
extra = 3
class QuestionAdmin(admin.ModelAdmin):
#fields=['pub_date','question_text']
fieldsets=[
(None, {'fields':['question_text']}),
('Date infomation', {'fields':['pub_date'],'classes':['collapse']}),
]
inlines = [ChoiceInline]
list_display = ('question_text', 'pub_date', 'was_published_recently')
list_filter = ['pub_date']
search_fields = ['question_text']
#admin.site.register(Question)
admin.site.register(Question,QuestionAdmin)
#admin.site.register(Choice)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步