Opened 7 years ago

Last modified 3 years ago

#11097 new Cleanup/optimization

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

Reported by: drozzy 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 7 years ago by drozzy

  • Keywords formset form inheritance id added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 6 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 5 years ago by julien

  • Severity set to Normal
  • Type set to Cleanup/optimization

comment:4 Changed 4 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:5 Changed 4 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:6 Changed 3 years ago by timo

Also reported in #20113

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