I have a model formset that I want to display 10 forms at a time using Django\'s Paginator, but it can\'t be done like paginator = Paginator(formset, 10)
. What\
Agree with Elrond Supports Monica. Fake attribute is interesting way to resolve the ordering error (Cannot reorder a query once a slice has been taken.)
But it can be fixed in one line also
queryset = queryset.order_by(Entry._meta.pk.name)
This fake ordering is need for avoid error in django.form.modelsBaseModelFormSet(BaseFormSet).get_queryset(): line #640
that make artificial ordering by pk but it impossible after slicing
(LIMIT-ations in SQL )
More detailed example
queryset = Entry.objects.all()
queryset = queryset.order_by(Entry._meta.pk.name)
paginator = Paginator(object_list=queryset, per_page=10)
page_obj = paginator.get_page(request.GET.get('page'))
EntryFormSet = modelformset_factory(Entry, EntryForm, extra=0)
entryformset = EntryFormSet(queryset=page_obj.object_list)