我正在尝试将内联表单集添加到表单中。这是重现错误的最少代码:
模型.py
class Festival(Model):
desc = TextField(max_length=1000)
class FestivalAddress(Model):
festival = ForeignKey(Festival, related_name="addresses")
name = CharField(max_length="50")
网址.py
urlpatterns = patterns('',
url('^add/$', FestivalCreateView.as_view(), name='festival_add'),
)
视图.py
class FestivalCreateView(CreateView):
model = Festival
form_class = FestivalForm
#Add FestivalAddressFormset to context here
表格.py
class FestivalAddressForm(ModelForm):
class Meta:
model = FestivalAddress
class FestivalForm(ModelForm):
class Meta:
model = Festival
FestivalAddressFormSet = inlineformset_factory(FestivalForm, FestivalAddress, form=FestivalAddressForm, extra=2)
这会引发 AttributeError:“ModelFormOptions”对象没有属性“get_parent_list”。我有点难过,因为我正在遵循SO 上给出的解决方案。
编辑:我删除了 FestivalCreateView 对表单集的使用,因为无论有没有它都会发生错误。