Ordering the forms within a formset? (How to override __iter__())

39 views
Skip to first unread message

Houmie

unread,
Sep 24, 2012, 7:04:31 PM9/24/12
to django...@googlegroups.com
deals_formset_factory = modelformset_factory(Deal, form=DealCForm, extra=1, can_delete=True, max_num=5)   
deals_formset
= deals_formset_factory(queryset=query)

Is there a way to say the one extra form shall always be the first form no matter how many more instance forms are within the deals_formset?

I found this bit in the documentation:

Iterating over the formset will render the forms in the order they were created. You can change this order by providing an alternate implementation for the __iter__() method.

Formsets can also be indexed into, which returns the corresponding form. If you override __iter__, you will need to also override __getitem__ to have matching behavior.

As I am still a bit new to python/django, I don't know where to begin. Is there any short example how __iter__() and __getitem() override have to look like?

many Thanks

Reply all
Reply to author
Forward
0 new messages