我正在Mezzanine做一个小博客用于学习目的,并希望通过对“mezzanine.pages.models.Page”进行子类化并使用admin注册此模型来添加自定义内容类型。我的课程看起来像这样:
models.py:
from django.db import models
from mezzanine.pages.models import Page
class Student(Page):
dob = models.DateField("Date of birth")
name = models.CharField("Name", max_length=30)
gender = models.CharField("Gender", max_length = 5, choices=(('M','Male'),
('F','Female')), default = 'M')
image = models.ImageField(upload_to='Students')
class Project(models.Model):
student = models.ForeignKey("Student")
project_image = models.ImageField(upload_to="StudentProjects")
admin.py:
from copy import deepcopy
from django.contrib import admin
from mezzanine.pages.admin import PageAdmin
from .models import Student, Project
student_extra_fieldsets = ((None, {"fields": ("dob","name","gender","image")}),)
class ProjectInline(admin.TabularInline):
model = Project
class StudentAdmin(PageAdmin):
inlines = (ProjectInline,)
fieldsets = deepcopy(PageAdmin.fieldsets) + student_extra_fieldsets
admin.site.register(Student, StudentAdmin)
现在,当我访问“http:// localhost:8000 / admin / pages / page /”添加我新注册的内容类型时,我得到一个没有名称的空选项,但是当我选择时我得到自定义内容输入“学生”页面进行添加和编辑。
由于我刚开始使用Django和Mezzanine,我不能简单地弄明白。
我使用“ sqlite ”作为后端而不使用“南”
指向这个的任何指针??
Thanx求助:)
答案 0 :(得分:0)
我在models.py中删除了“ * name = models.CharField(”Name“,max_length = 30)* ”并将其替换为:
first_name = models.CharField("First Name", max_length=30)
last_name = models.CharField("Last Name", max_length=30)
现在一切似乎都好!! (只有我使用“南”