Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#23672 closed New feature (wontfix)

Add “instances” argument to BaseModelFomSet.__init__()

Reported by: aki33524 Owned by: nobody
Component: Forms Version: 1.7
Severity: Normal Keywords: BaseModelFormset
Cc: tzanke@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by aki33524)

There are two reasons.

First, as you know, ModelForm can accept instance as keyword arguments.
I think that BaseModelFormSet should follow this. Current BaseModelFormSet support save(commit=False), which returns “instances”. But now, we cannot use it without INSERT in DataBase..

Second, Current BaseModelFormSet accepts “queryset” as keyword argument.
“queryset” can convert to “instances”, but “instances” cannot convert to “queryset”. I think that BaseModelFormSet should accept not “queryset” but “instances”.

For downward compatible, it would be difficult that “instances” replace with “queryset”. So I suggest adding “instances” argument to BaseModelFormSet init.

Change History (6)

comment:1 by aki33524, 10 years ago

Summary: Add “instances” argument to BaseModelFomset.__init__()Add “instances” argument to BaseModelFomSet.__init__()

comment:2 by aki33524, 10 years ago

Description: modified (diff)

comment:3 by Collin Anderson, 10 years ago

Are you just proposing a name change, or would it function different than how queryset currently functions?

in reply to:  3 comment:4 by aki33524, 10 years ago

Replying to collinanderson:

Are you just proposing a name change, or would it function different than how queryset currently functions?

A 'QuerySet' represents a collection of objects from your database.

AuthorFormSet = modelformset_factory(Author, max_num=1)
formset = AuthorFormSet(queryset=Author.objects.filter(name__startswith='O'))

On the other hand, 'instances' which I propose, DON'T NEED to be INSERTed in database.

AuthorFormSet = modelformset_factory(Author, max_num=1)
instances = [Author() for i in range(10)]
formset = AuthorFormSet(instances=instances)

It follows ModelForm.

a = Author()
f = AuthorForm(request.POST, instance=a)

For example, I tryed to store 'instances', which is returned by formset.save(commit=False), in session. In other words, instances don't be INSERTed. Then I want to INSERT these instances in database at last.This application can modify these instances, current BaseModelFormSet cannot do it.

comment:5 by Tim Graham, 10 years ago

Resolution: wontfix
Status: newclosed

I think your use case could be solved by using initial data and an empty QuerySet. I don't think adding more complexity to formsets is the answer, but if I've missing something please reopen with more details. Thanks.

comment:6 by TZanke, 9 years ago

Cc: tzanke@… added
Note: See TracTickets for help on using tickets.
Back to Top