django part2 --- admin

admin后台是针对管理者的,而不是针对用户
创建管理员
E:\paython学习\pycharm\mysite>python manage.py createsuperuser
Username (leave blank to use 'dinghuan'): admin
Email address: [email protected]
Password:
Password (again):
Superuser created successfully.

在1.7以前,都是在python manage.py syncdb时创建的, 1.7之后用的是python manage.py migrate了,所以要重新创建管理员

python manage.py runserver 127.0.0.1:8000

http://127.0.0.1:8000/admin
并不能看到我们的question,choice,要先注册才能在后台管理
polls.admin.py from django.contrib import admin
from polls.models import Question,Choice
# Register your models here.
class ChoiceInline(admin.StackedInline):
    model = Choice
    extra = 3

class QuestionAdmin(admin.ModelAdmin):
  #  fileds = ['pub_date', 'question_text']
    list_display = ('question_text','pub_date','was_published_recently')
    list_filter = ['pub_date']                                                        //pub_date字段可排序
    search_fields = ['question_text']                                                 //有一个搜寻窗口
    fieldsets = [                                                                     //按照fieldsets布局
        (None, {'fields':['question_text']}),
        ('Date information', {'fields':['pub_date'],'classes':['collapse']}),
    ]
    inlines = [ChoiceInline]                                                          //在question里设置choice
admin.site.register(Question,QuestionAdmin)
admin.site.register(Choice) 



django part2 --- admin_第1张图片

django part2 --- admin_第2张图片
django 可以定制admin页面,这些都是后台,后面介绍前台的内容

你可能感兴趣的:(django,admin)