创建超级用户
$ python manage.py createsuperuser
启动开发服务器
$ python manage.py runserver
让应用在管理界面中可编辑
$ cat tasks/admin.py from django.contrib import admin # Register your models here. from .models import *
自定义管理表单
$cat tasks/admin.py from django.contrib import admin # Register your models here. from .models import * class QuestionsAdmin(admin.ModelAdmin): fileds = [‘pub_date‘ , ‘question_text‘]
管理界面表单自定义
$ cat tasks/admin.py from django.contrib import admin # Register your models here. from .models import * class ChoiceInline(admin.TabularInline): model = Choice extra = 3 class QuestionsAdmin(admin.ModelAdmin): #fileds = [‘pub_date‘ , ‘question_text‘] filtedsets=[ (None , {‘fields‘ : [‘question_text‘]}), (‘Date information‘ ,{‘fileds‘:[‘pub_date‘],‘classes‘: [‘collapse‘]}), ] list_display = (‘question_text‘, ‘pub_date‘) inlines = [ChoiceInline] admin.site.register(Questions , QuestionsAdmin)
自定义管理站点的首页面
需要自定义的模板文件是 admin/index.html。 (就像之前对admin/base_site.html做的那样 —— 即从默认的目录拷贝到你自定义的目录中的那个文件)。
时间: 2024-10-26 10:20:57