我希望能够在modelformset_factory中使用自定义表单。例如:
models.py
class Author(models.Model):
name = models.CharField()
address = models.CharField()
class AuthorForm(ModelForm):
class Meta:
model = Author
views.py
def test_render(request):
myModelFormset = modelformset_factory(Author)
items = Author.objects.all()
formsetInstance = myModelFormset(queryset = items)
return render_to_response('template',locals())
上面的代码工作正常,但请注意我没有使用AuthorForm。问题是如何让modelformset_factory使用AuthorForm(我计划稍后自定义)而不是制作默认的Author表单?
答案 0 :(得分:21)
我认为您应该能够像这样传递自定义模型表单:
myModelFormset = modelformset_factory(Author, form=AuthorForm)