Proposal: by default, don't populate a modelformset with all model instances.

67 views
Skip to first unread message

Wim Feijen

unread,
Dec 27, 2015, 10:00:35 AM12/27/15
to Django developers (Contributions to Django itself)
By default, when you create a formset from a model, the formset will use a queryset that includes all objects in the model (e.g., Author.objects.all()). 

In most use cases, people will want to use a specific subset of data and will construct queryset by hand. Or they want to use an empty queryset, just to add data.

In my opinion it would be better to set the empty queryset as a default. 

Do you agree?

Then I will make a ticket and maybe add a patch.

Russell Keith-Magee

unread,
Dec 27, 2015, 7:11:43 PM12/27/15
to Django Developers
On Sun, Dec 27, 2015 at 11:00 PM, Wim Feijen <w...@go2people.nl> wrote:
By default, when you create a formset from a model, the formset will use a queryset that includes all objects in the model (e.g., Author.objects.all()). 

In most use cases, people will want to use a specific subset of data and will construct queryset by hand. Or they want to use an empty queryset, just to add data.

In my opinion it would be better to set the empty queryset as a default. 

Do you agree?

I think both potential defaults are completely arbitrary. One represents “Edit everything that is currently available”; the other represents “Give me the ability to add new things”. Which one is a “more appropriate” default will ultimately come down to your own use cases.

However, even if your *were* completely correct in saying that the second interpretation was a more common one, it would be exceedingly difficult to make this change because of backwards compatibility. For that reason alone, I’d suggest that this proposal isn’t likely to go very far.

Yours,
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages