Opened 13 years ago

Closed 3 years ago

Last modified 3 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 Changed 13 years ago by Andriy Drozdyuk

Keywords: formset form inheritance id added

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

Triage Stage: UnreviewedAccepted

comment:3 Changed 11 years ago by Julien Phalip

Severity: Normal
Type: Cleanup/optimization

comment:4 Changed 10 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 Changed 10 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:6 Changed 9 years ago by Tim Graham

Also reported in #20113

comment:7 Changed 3 years ago by Mariusz Felisiak

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

comment:8 Changed 3 years ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 0b7378db:

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

comment:9 Changed 3 years ago by Mariusz Felisiak <felisiak.mariusz@…>

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 Changed 3 years ago by Mariusz Felisiak <felisiak.mariusz@…>

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