Opened 16 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 , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:3 by , 13 years ago
UI/UX: | unset |
---|
comment:5 by , 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 , 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 , 10 years ago
Has patch: | set |
---|---|
Type: | Bug → Cleanup/optimization |
comment:12 by , 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:14 by , 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:16 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:18 by , 8 years ago
Component: | Database layer (models, ORM) → Documentation |
---|---|
Patch needs improvement: | set |
Summary: | Proxy models do not inherit META.app_label → Document that proxy model Meta inheritance works like normal models |
comment:21 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Change UI/UX from NULL to False.