admin.py

1
from django.contrib import admin

创建一个管理员用户:

1
$ python manage.py createsuperuser

管理员登陆界面:

1
http://localhost:8080/admin/

在admin.py中注册模型,然后就可以在登陆界面管理模型了

1
2
from .models import Question
admin.site.register(Question)

自定义管理表单:

1
2
3
4
from .models import Question
class QuestionAdmin(admin.ModelAdmin):
    fileds = ['pub_date', 'question_date']
admin.site.register(Question, QuestionAdmin)

把表单分割成字段集:

1
2
3
4
5
6
7
from .models import Question
class QuestionAdmin(admin.ModelAdmin):
    fieldsets = [
        (None,               {'fields': ['question_text']}),
        ('Date information', {'fields': ['pub_date']}),
    ]
admin.site.register(Question, QuestionAdmin)

后台

django的后台管理程序。