Opened 8 years ago

Closed 2 months ago

#11078 closed Cleanup/optimization (fixed)

Document that proxy model Meta inheritance works like normal models

Reported by: George Song Owned by: Jonatas CD
Component: Documentation Version: master
Severity: Normal Keywords: proxy model app_label
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

According to the proxy model documentation:
"Proxy models inherit any Meta options that they don't define from their non-abstract model parent (the model they are proxying for)."

In the case of app_label, this is not true.

from django.db import models

class Book(models.Model):
    name = models.CharField(max_length=50)

    class Meta:
        app_label = 'core'

class Book1(Book):
    class Meta:
        proxy = True

>>> from django.db import models
>>> for model in models.get_models(): print model._meta
...
core.book
proxy.book1

Change History (21)

comment:1 Changed 7 years ago by Alex Gaynor

Triage Stage: UnreviewedAccepted

comment:2 Changed 6 years ago by Julien Phalip

Severity: Normal
Type: Bug

comment:3 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 Changed 2 years ago by Aymeric Augustin

This still happens after the app-loading refactor.

I couldn't locate the code that copies the original model's meta attributes to the proxy's meta. It looks like it could be Options.setup_proxy but that method only deals with a few attributes.

comment:6 Changed 20 months ago by Marco Santamaria

Only the 'ordering' and 'get_latest_by' meta attributes get copied in the new method of ModelBase.

Therefore, if a meta attribute is not in ['ordering', 'get_latest_by'], it will not be inherited by the Meta class in the proxy model.

A pull request that removes that statement from the documentation has been proposed. See https://github.com/django/django/pull/4531

comment:7 Changed 20 months ago by Marco Santamaria

Has patch: set
Type: BugCleanup/optimization

comment:8 Changed 20 months ago by Marco Santamaria <marco.santamaria@…>

Resolution: fixed
Status: newclosed

In bae72bd:

Fixed #11078 -- documentation update.

comment:9 Changed 20 months ago by Florian Apolloner <apollo13@…>

In cc493d3c:

Merge pull request #4531 from marco-santamaria/ticket11078

Fixed #11078 -- documentation update.

comment:10 Changed 20 months ago by Tim Graham <timograham@…>

In 1e0bf2c:

[1.8.x] Fixed #11078 -- Removed inaccurate docs about proxy models Meta.

Backport of bae72bdd2aa93472617ed28fc3d5a01f0920ea6e from master

comment:11 Changed 20 months ago by Tim Graham <timograham@…>

In 276f760:

[1.7.x] Fixed #11078 -- Removed inaccurate docs about proxy models Meta.

Backport of bae72bdd2aa93472617ed28fc3d5a01f0920ea6e from master

comment:12 Changed 20 months ago by Germano Gabbianelli

I don't think we fixed this correctly. The doc was indeed wrong about inheriting "any Meta options", but the 'ordering' and 'get_latest_by' meta attributes are still copied to the new model.

This is why I think this behaviour should be either documented or removed.

comment:13 Changed 20 months ago by Tim Graham

Has patch: unset
Resolution: fixed
Status: closednew

Agreed.

comment:14 Changed 2 months ago by Jonatas CD

So, I'd say that, for now, it's better to document the current behavior and then set to discussion if it's still the expected behavior or not. Based on that eventually open or not a new ticket to change that. Correct?

comment:15 Changed 2 months ago by Tim Graham

Sure.

comment:16 Changed 2 months ago by Jonatas CD

Owner: changed from nobody to Jonatas CD
Status: newassigned

comment:17 Changed 2 months ago by Jonatas CD

Has patch: set

comment:18 Changed 2 months ago by Tim Graham

Component: Database layer (models, ORM)Documentation
Patch needs improvement: set
Summary: Proxy models do not inherit META.app_labelDocument that proxy model Meta inheritance works like normal models

comment:19 Changed 2 months ago by Tim Graham <timograham@…>

In e8728f0:

Refs #11078 -- Doc'd Meta inheritance in proxy models.

comment:20 Changed 2 months ago by Tim Graham <timograham@…>

In fbf59a29:

[1.10.x] Refs #11078 -- Doc'd Meta inheritance in proxy models.

Backport of e8728f03f0bfbdb555be0a663d1608e1991d10a6 from master

comment:21 Changed 2 months ago by Tim Graham

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.
Back to Top