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