0

当我将布尔字段添加到作为内联到主模型中的直通成员时,我有一个奇怪的行为。保存后,它会随机将该字段显示为 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):
        # [...]

任何的想法?

4

1 回答 1

0

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

于 2013-09-23T11:36:15.833 回答