我正在创建一个示例,以了解有关使用SessionWizard的内联表单集的更多信息.最后,我想集成动态表单集,以便在提交之前通过模板添加和删除单个表单.但是,当第二种形式中没有数据时,它不能像常规ModelForm那样进行验证.
SessionWizard中是否有需要覆盖的方法?这是Django内在处理的东西吗?
非常感谢指导和实例.
models.py
class Parent(models.Model):
name = models.CharField(max_length=256)
def __unicode__(self):
return name
class Child(models.Model):
name = models.CharField(max_length=256)
parent = models.ForeignKey(Parent)
def __unicode__(self):
return name
Run Code Online (Sandbox Code Playgroud)
urls.py
test_forms = [['parent', ParentForm],['child', ChildFormSet]]
urlpatterns = patterns('example.views',
url(r'^$', TestWizard.as_view(test_forms)),
)
Run Code Online (Sandbox Code Playgroud)
forms.py
class ParentForm(ModelForm):
class Meta:
model = Parent
class ChildForm(ModelForm):
class Meta:
model = Child
exclude = ('parent',)
ChildFormSet = inlineformset_factory(Parent, Child, extra=1)
class TestWizard(SessionWizardView):
"""
This WizardView is used to create multi-page forms and handles all the
storage and validation stuff using …Run Code Online (Sandbox Code Playgroud)