Opened 4 years ago

Closed 4 years ago

Last modified 6 months ago

#20113 closed Cleanup/optimization (duplicate)

Documentation on _ptr and _ptr_id use in multi-table inheritance

Reported by: anonymous Owned by: nobody
Component: Documentation Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

The documentation on "Multi-table inheritance" does not mention the naming of the (generated) primary / foreign key field of the inheriting table (which becomes place_ptr_id in the Place / Restaurant example).

If I use instance data from that model in a template, and want to render the fields myself, I need that name, as described in "Using the formset in the template":

<form method="post" action="">
    {{ formset.management_form }}
    {% for form in formset %}
        {{ form.place_ptr }}
        <ul>
            <li>{{ ... }}</li>
        </ul>
    {% endfor %}
</form>

Confusingly, the name which should be used here is "place_ptr", not "place_ptr_id", which it is in the database (using "place_ptr_id" in the template gives a MultiValueDictKeyError). Since this is not documented (or I haven't found it, though I did search!), I suggest adding something to the "Multi-table inheritance" documentation which explains how the auto-generated field can be used in templates as "place_ptr".

Change History (3)

comment:1 Changed 4 years ago by marc@…

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 4 years ago by Tim Graham

Resolution: duplicate
Status: newclosed

Duplicate of #11097

comment:3 Changed 6 months ago by Tim Graham

Component: UncategorizedDocumentation
Description: modified (diff)
Type: UncategorizedCleanup/optimization
Note: See TracTickets for help on using tickets.
Back to Top