Opened 7 years ago
Closed 7 years ago
#24693 closed Cleanup/optimization (fixed)
Add model Options.label property
Reported by: | Tim Graham | Owned by: | Luis Del Giudice |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Markus Holtermann, alasdair@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
There are many places in Django that construct a dotted path like this:
'%s.%s' % (model._meta.app_label, model._meta.object_name)
It would by DRYer to add a property to the Options class in django/db/models/options.py that returned the dotted path. I'm proposing the name "label".
Change History (17)
comment:1 Changed 7 years ago by
comment:3 Changed 7 years ago by
Owner: | changed from nobody to John Giannelos |
---|---|
Status: | new → assigned |
comment:4 Changed 7 years ago by
We also want to add a label_lower
property that returns '%s.%s' % (model._meta.app_label, model._meta.model_name)
as that's another repeated pattern.
comment:5 Changed 7 years ago by
What's the advantage of doing options.label_lower
rather than options.label.lower()
?
Or are these two different things?
comment:6 Changed 7 years ago by
Cc: | Markus Holtermann added |
---|
options.app_label
is never converted to lower case.
comment:8 Changed 7 years ago by
Owner: | changed from John Giannelos to Luis Del Giudice |
---|
comment:10 Changed 7 years ago by
Has patch: | set |
---|---|
Needs documentation: | set |
Needs tests: | set |
Patch needs improvement: | set |
comment:11 Changed 7 years ago by
About the documentation for this PR: I think we should make options.label
and options.label_lower
public API.
comment:12 Changed 7 years ago by
I've added tests, changes in the docs, looked for places in django source code old labels were used and replaced with model._meta.label
or model._meta.label_lower
comment:13 Changed 7 years ago by
Needs documentation: | unset |
---|---|
Needs tests: | unset |
comment:14 Changed 7 years ago by
Patch needs improvement: | unset |
---|
comment:15 Changed 7 years ago by
Cc: | alasdair@… added |
---|
comment:16 Changed 7 years ago by
Triage Stage: | Accepted → Ready for checkin |
---|
Yes please!