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 saving 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__.
--
Ticket URL: <https://code.djangoproject.com/ticket/23672>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/23672#comment:1>
Old description:
> 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 saving 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__.
New description:
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__.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/23672#comment:2>
Comment (by collinanderson):
Are you just proposing a name change, or would it function different than
how `queryset` currently functions?
--
Ticket URL: <https://code.djangoproject.com/ticket/23672#comment:3>
Comment (by aki33524):
Replying to [comment:3 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/23672#comment:4>
* status: new => closed
* resolution: => wontfix
Comment:
I think your use case could be solved by using
[https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#providing-
initial-values initial data] and
[https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#changing-
the-queryset 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/23672#comment:5>
* cc: tzanke@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/23672#comment:6>