Opened 10 years ago

Last modified 6 years ago

#11097 new Cleanup/optimization

Formset documentation should include a note about form.blah_ptr for derived models

Reported by: Andriy Drozdyuk Owned by: nobody
Component: Documentation Version: 1.0
Severity: Normal Keywords: formset, form, inheritance, id
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Whenever a model inherits from a non-abstract model, it shares it's primary key with it.
As a consequence, the form produced by inlineformset_factory no longer has id field, by the "parentname_ptr" field.

For example imagine you have a case such as:

class Car(models.Model):
    color = #string field

class BMW(Car):
    shop = models.ForeignKey(CarShop)

Then in our view:

car = BMW.objects.get(pk=1)
BMWFromset = inlineformset_factory(CarShop, BMW, 
formset = BMWFormset(instance=car)

The in our html:

<form method="post">
	{% for form in formset.forms %}
        <!-- NOTICE that we do NOT use here -->
        {% endfor %}
<input type="submit"  value="submit" />

Change History (6)

comment:1 Changed 10 years ago by Andriy Drozdyuk

Keywords: formset form inheritance id added

comment:2 Changed 9 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

comment:3 Changed 8 years ago by Julien Phalip

Severity: Normal
Type: Cleanup/optimization

comment:4 Changed 7 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 Changed 7 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:6 Changed 6 years ago by Tim Graham

Also reported in #20113

Note: See TracTickets for help on using tickets.
Back to Top