Using a custom form in a modelformset factory?

Posted by jamida on Stack Overflow See other posts from Stack Overflow or by jamida
Published on 2010-05-17T22:28:41Z Indexed on 2010/05/17 22:30 UTC
Read the original article Hit count: 458

I'd like to be able to use a customized form in a modelformset_factory. For example:

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())

The above code works just fine, but note I'm NOT using AuthorForm. The question is how can I get the modelformset_factory to use the AuthorForm (which I plan to customize later) instead of making a default Author form?

© Stack Overflow or respective owner

Related posts about django

Related posts about django-models