Opened 15 years ago

Closed 8 years 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: dev
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 by Alex Gaynor, 15 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Julien Phalip, 13 years ago

Severity: Normal
Type: Bug

comment:3 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 by Aymeric Augustin, 10 years ago

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 by Marco Santamaria, 10 years ago

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 by Marco Santamaria, 10 years ago

Has patch: set
Type: BugCleanup/optimization

comment:8 by Marco Santamaria <marco.santamaria@…>, 10 years ago

Resolution: fixed
Status: newclosed

In bae72bd:

Fixed #11078 -- documentation update.

comment:9 by Florian Apolloner <apollo13@…>, 10 years ago

In cc493d3c:

Merge pull request #4531 from marco-santamaria/ticket11078

Fixed #11078 -- documentation update.

comment:10 by Tim Graham <timograham@…>, 10 years ago

In 1e0bf2c:

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

Backport of bae72bdd2aa93472617ed28fc3d5a01f0920ea6e from master

comment:11 by Tim Graham <timograham@…>, 10 years ago

In 276f760:

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

Backport of bae72bdd2aa93472617ed28fc3d5a01f0920ea6e from master

comment:12 by Germano Gabbianelli, 10 years ago

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 by Tim Graham, 10 years ago

Has patch: unset
Resolution: fixed
Status: closednew

Agreed.

comment:14 by Jonatas CD, 8 years ago

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 by Tim Graham, 8 years ago

Sure.

comment:16 by Jonatas CD, 8 years ago

Owner: changed from nobody to Jonatas CD
Status: newassigned

comment:17 by Jonatas CD, 8 years ago

Has patch: set

comment:18 by Tim Graham, 8 years ago

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 by Tim Graham <timograham@…>, 8 years ago

In e8728f0:

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

comment:20 by Tim Graham <timograham@…>, 8 years ago

In fbf59a29:

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

Backport of e8728f03f0bfbdb555be0a663d1608e1991d10a6 from master

comment:21 by Tim Graham, 8 years ago

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