Code

Opened 4 years ago

Closed 4 years ago

#14379 closed (invalid)

formset.is_bound returns False for ModelFormsets created with queryset as argument

Reported by: jnns Owned by: nobody
Component: Forms Version: master
Severity: Keywords: modelformset bound
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When a Modelformset is instantiated via a queryset, its is_bound attribute returns False although all of its forms are linked to instances of the queryset. This seems a bit odd to me because formset and forms are bound as soon as the Modelformset is instantiated via data (i.e. request.POST).

>>> from django.forms.models import modelformset_factory
>>> from models import Testobject

>>> TestFormset = modelformset_factory(Testobject)
>>> formset = TestFormset(queryset=Testobject.objects.all())

>>> formset.is_bound 
False
>>> formset.forms[0].is_bound
False
>>> formset.forms[0].instance
Testobject object

Attachments (0)

Change History (1)

comment:1 Changed 4 years ago by Honza_Kral

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

This is correct behavior - instantiating ModelFormSet with a queryset is the equivalent of supplying initial to a Form which also isn't bound in that case.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.