Opened 15 years ago

Closed 5 years ago

Last modified 5 years ago

#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 Andriy Drozdyuk, 15 years ago

Keywords: formset form inheritance id added

comment:2 by Russell Keith-Magee, 15 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Julien Phalip, 13 years ago

Severity: Normal
Type: Cleanup/optimization

comment:4 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:6 by Tim Graham, 12 years ago

Also reported in #20113

comment:7 by Mariusz Felisiak, 5 years ago

Has patch: set
Owner: changed from nobody to Mac Chapman
Status: newassigned
Version: 1.0master

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 0b7378db:

Fixed #11097 -- Added note about parent link fields in formsets for multi-table inheritance models.

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 56061de:

[3.0.x] Fixed #11097 -- Added note about parent link fields in formsets for multi-table inheritance models.

Backport of 0b7378db1fdd7bfc7b78089811b3abb722c4ba95 from master

comment:10 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 8c1b492e:

[2.2.x] Fixed #11097 -- Added note about parent link fields in formsets for multi-table inheritance models.

Backport of 0b7378db1fdd7bfc7b78089811b3abb722c4ba95 from master

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