Opened 16 years ago
Closed 15 years ago
#10263 closed (fixed)
order_by parameter for inlineformset_factory and BaseInlineFormSet
Reported by: | 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)
Change History (12)
by , 16 years ago
Attachment: | inlineformset_factory_order_by.diff added |
---|
comment:2 by , 16 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
marking as design decision needed, why not just pass the queryset already ordered?
comment:3 by , 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 , 16 years ago
Attachment: | inline_formset_queryset_argument.diff added |
---|
New patch as sugested by Alex
comment:4 by , 16 years ago
New patch adds a queryset argument to BaseInlineFormSet making it consistent with BaseModelFormset, as sugested by Alex.
by , 16 years ago
Attachment: | inline_formset_queryset_argument_2.diff added |
---|
Chained the fk filter even if queryset provided, as sugested by Alex.
by , 16 years ago
Attachment: | inlineformset_queryset_parameter.diff added |
---|
comment:6 by , 15 years ago
Triage Stage: | Design decision needed → Accepted |
---|
comment:7 by , 15 years ago
Cc: | added |
---|
comment:8 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Patch to add order_by parameter for inlineformset_factory