#11097 closed Cleanup/optimization (fixed)
Formset documentation should include a note about form.blah_ptr for derived models
| Reported by: | Andriy Drozdyuk | Owned by: | Mac Chapman |
|---|---|---|---|
| Component: | Documentation | Version: | dev |
| Severity: | Normal | Keywords: | formset, form, inheritance, id |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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,
can_delete=True,
extra=1)
formset = BMWFormset(instance=car)
The in our html:
<form method="post">
{{formset.management_form}}
<ul>
{% for form in formset.forms %}
<li>
<!-- NOTICE that we do NOT use form.id here -->
{{form.car_ptr}}
{{form}}
</li>
{% endfor %}
</ul>
<input type="submit" value="submit" />
</form>
Change History (10)
comment:1 by , 17 years ago
| Keywords: | formset form inheritance id added |
|---|
comment:2 by , 16 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 15 years ago
| Severity: | → Normal |
|---|---|
| Type: | → Cleanup/optimization |
comment:4 by , 14 years ago
| UI/UX: | unset |
|---|
comment:7 by , 6 years ago
| Has patch: | set |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
| Version: | 1.0 → master |
Note:
See TracTickets
for help on using tickets.
Change UI/UX from NULL to False.