InlineModelAdmin class InlineModelAdminclass TabularInlineclass StackedInline 举例,有两个Model: from django.db import models class Author(models.Model): name = models.CharField(max_length=100) class Book(models.Model): author = models.ForeignKey(Author) t…
1.自定义模板设置: ModelAdmin. add_form_template Path to a custom template, used by add_view(). ModelAdmin. change_form_template Path to a custom template, used by change_view(). ModelAdmin. change_list_template Path to a custom template, used by changelist_…
1. ModelAdmin.inlines 将有外键的子类包含进视图 ,实例: class Author(models.Model): name = models.CharField(max_length=100) class Book(models.Model): author = models.ForeignKey(Author) title = models.CharField(max_length=100) class BookInline(admin.TabularInline): m…
一:基础设置 1.应用注册 1)方式一 若要把app应用显示在后台管理中,需要在admin.py中注册.打开admin.py文件,如下代码: from django.contrib import admin from blog.models import Blog #Blog模型的管理器(自定制显示内容类) class BlogAdmin(admin.ModelAdmin): list_display=('id', 'caption', 'author', 'publish_time') #在a…
通过自定义Admin的模板文件实现省市区的三级联动.要求创建记录时,根据省>市>区的顺序选择依次显示对应数据. 修改记录时默认显示已存在的数据. Model class Member(models.Model): name = models.CharField(max_length=100, verbose_name='姓名') province = models.CharField(max_length=100, null=True, blank=True, verbose_name='省份…