django管理员和内联

时间:2013-06-17 14:19:07

标签: django django-models django-admin

当我将booleanfield添加到一个直接的memebership时,我有一个奇怪的行为,它被作为内联包含在主模型中。保存后,它会将字段随机显示为True / False。无论数据库上有什么。

class Project(models.Model):
    # Relations with other entities.
    employees = models.ManyToManyField('staff.Person', through='project.PersonProjectMembership',
                                       related_name='projects')
class PersonProjectMembership(models.Model):
    project = models.ForeignKey('project.Project', related_name="person_memberships")
    person = models.ForeignKey('staff.Person', related_name="project_memberships")
    lead = models.BooleanField(default=False)

class ProjectAdmin(TranslationAdmin, ModelAdmin):
    inlines = (PersonProjectMembershipInline,)

class PersonProjectMembershipInline(TranslationStackedInline, admin.StackedInline):
    model = Project.employees.through
    extra = 1
    formset = PersonProjectMembershipInlineFormSet

class PersonProjectMembershipInlineFormSet(BaseInlineFormSet):
    def clean(self):
        # [...]

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

已经有一段时间了。问题出在一些验证器中,我在其中覆盖了PersonProjectMembership.lead值。