【问题标题】:Custom content type appears with an empty option in the admin "add type of page" page in mezzanine夹层的管理“添加页面类型”页面中的自定义内容类型显示为空选项
【发布时间】:2012-08-25 05:02:28
【问题描述】:

我在 Mezzanine 中写了一个小博客,用于学习目的,并希望通过子类化“mezzanine.pages.models.Page”来添加自定义内容类型并向管理员注册此模型。我的课程看起来像这样:

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”作为后端,而不是使用“South

任何指向这个的指针??

感谢您的帮助:)

【问题讨论】:

    标签: django mezzanine


    【解决方案1】:

    我删除了 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)
    

    现在一切似乎都很好! (仅当我使用“South”时

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多