modelformset and pagination?

207 views
Skip to first unread message

Some Guy

unread,
Nov 25, 2009, 11:46:55 PM11/25/09
to Django users
I'm having an issue trying to create pagination with a modelformset.
so far I have...

SubFormSet = modelformset_factory(Submission, can_delete=True,
extra=0, form=PricingForm)
...
objs = Submission.objects.all()
formset = SubFormSet(queryset=objs) <-overriding the basic
queryset
groups = map(None, objs, formset.forms) <- I need both the objects
and the forms, iterating over them together in the view
paginator = Paginator(groups, 10) <-- standard paginator
this_page = paginator.page(ppage)
...then render

so, basically, this works for viewing, but submitting doesn't work
because the management form values (INITIAL_FORMS, FORM_COUNT, etc)
are wrong, they still hold the values of the whole queryset. I tried
feeding the formset constructor the object_list from the paginiator,
but that fails, complaining about "is_ordered" not being there.So my
considerations are to...

1.Change the management form values with js (scary at best)
2.Slice the queryset (seems like i'd have to duplicate all the
pagination in my code)
3.Try to overwrite the management_form values directly.
4.Set the max_num attribute of the model_formset
5.beg for help on the mailing list. :)

Anyone have any guidance as to which might be best option? Anyone ever
done this?
TIA

Some Guy

unread,
Nov 26, 2009, 2:01:57 AM11/26/09
to Django users
well, I've looked into it more, and it seems that the max_num argument
to the modelformset_factory constructor is the best way to go. If it
works i'll post it here for those who might find this thread from
google.
Reply all
Reply to author
Forward
0 new messages