Opened 16 years ago

Closed 15 years ago

#10263 closed (fixed)

order_by parameter for inlineformset_factory and BaseInlineFormSet

Reported by: Paulo Scardine <paulo@…> Owned by: nobody
Component: Forms Version: 1.0
Severity: Keywords: inlineformset_factory BaseInlineFormSet inline model formset
Cc: andy@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Problem

At inlineformset_factory and BaseInlineFormSet constructor there is no option to specify order_by criteria for the resulting queryset.

The record order at the rendered formset will depend on the order returned by the database layer; notably PostgreSQL may change this order after every update. When using PRG (Post/Redirect/Get) the result is unpleasant and may confuse users.

Proposed Solution

I would like to add an order_by parameter to inlineformset_factory and BaseInlineFormSet.

Attachments (4)

inlineformset_factory_order_by.diff (2.3 KB ) - added by Paulo Scardine <paulo@…> 16 years ago.
Patch to add order_by parameter for inlineformset_factory
inline_formset_queryset_argument.diff (5.6 KB ) - added by paulos 16 years ago.
New patch as sugested by Alex
inline_formset_queryset_argument_2.diff (5.6 KB ) - added by paulos 16 years ago.
Chained the fk filter even if queryset provided, as sugested by Alex.
inlineformset_queryset_parameter.diff (5.5 KB ) - added by paulos 16 years ago.

Download all attachments as: .zip

Change History (12)

by Paulo Scardine <paulo@…>, 16 years ago

Patch to add order_by parameter for inlineformset_factory

comment:1 by Carl Meyer, 16 years ago

Related: #9758, #9006.

comment:2 by Alex Gaynor, 16 years ago

Triage Stage: UnreviewedDesign decision needed

marking as design decision needed, why not just pass the queryset already ordered?

comment:3 by anonymous, 16 years ago

At first it also looked like a good idea to pass a queryset ready.

But giving it some thought to this issue, my opinion changed. I think the purpose of inlineformset_factory is very specific: making a formset linked by the parent_model PK.

So what is the point of passing a queryset as argument? If it is for flexibility, it seems out of place, because we should address the common use case and not the exception.

If you could make the point for a broader solution I will be happy to provide a patch.

by paulos, 16 years ago

New patch as sugested by Alex

comment:4 by paulos, 16 years ago

New patch adds a queryset argument to BaseInlineFormSet making it consistent with BaseModelFormset, as sugested by Alex.

by paulos, 16 years ago

Chained the fk filter even if queryset provided, as sugested by Alex.

comment:5 by paulos, 16 years ago

Last patch is a little better styled (won't trigger evaluation).

comment:6 by Alex Gaynor, 16 years ago

Triage Stage: Design decision neededAccepted

comment:7 by anonymous, 16 years ago

Cc: andy@… added

comment:8 by Russell Keith-Magee, 15 years ago

Resolution: fixed
Status: newclosed

(In [11874]) Fixed #10263 -- Added a queryset argument to BaseInlineFormSet, normalizing with BaseModelFormSet, and allowing for custom ordering/subsets in inlines. Thanks to Paulo Scardine for the patch.

Note: See TracTickets for help on using tickets.
Back to Top