Code

Opened 5 years ago

Last modified 16 months 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

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>

Attachments (0)

Change History (6)

comment:1 Changed 5 years ago by drozzy

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

comment:2 Changed 4 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 3 years ago by julien

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

comment:4 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:5 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:6 Changed 16 months ago by timo

Also reported in #20113

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.