Skip to content Skip to sidebar Skip to footer

Modelformset __iter__ Overloading Problem

I'm writing the custom modelformset. I need that forms to be sorted by value of field 'ordering'. I overloaded __iter__ method of BaseFormSet in my child formset class. My class in

Solution 1:

Not familiar enough with Django to judge whether this is the right way, but here's a simple gotcha:

return iter(self.forms.sort( ...

sort() is a method on a list that sorts it in-place and returns None. You probably meant:

returniter(sorted(self.forms, ...

Post a Comment for "Modelformset __iter__ Overloading Problem"