#25880: Forms created by formset_factory's extra parameter don't have instance 
set
----------------------------+--------------------
     Reporter:  karyon      |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Forms       |    Version:  1.8
     Severity:  Normal      |   Keywords:
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0           |      UI/UX:  0
----------------------------+--------------------
 i have code of the following form:


 {{{

 Model A:
     pass

 Model B:
     related_field = ForeignKey(A)


 class BForm(ModelForm):

     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
         print(self.instance.related_field)


 def some_view(request):
     InlineBFormset = inlineformset_factory(A, B, formset=ABFormset,
 form=BForm, extra=1)

     formset = InlineBFormset(request.POST or None,
 instance=some_a_instance)


 }}}

 the line with the print crashes for the form created by the extra=1 with
 RelatedObjectDoesNotExist: B has no A. i would have expected that the
 some_a_instance is set on the form's self.instance.

 in django 1.9, i can easily work around that by handing over constructor
 parameters, but it would still seem weird to me to hand over the related
 instance that would later be set by the formset's save method anyways.

 i can provide the real code if needed.

--
Ticket URL: <https://code.djangoproject.com/ticket/25880>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.f5ab52d375bc255fac3764ea8507aad3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to