Opened 10 years ago
Closed 10 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 by , 10 years ago
comment:3 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 10 years ago
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 by , 10 years ago
What's the advantage of doing options.label_lower
rather than options.label.lower()
?
Or are these two different things?
comment:8 by , 10 years ago
Owner: | changed from | to
---|
comment:10 by , 10 years ago
Has patch: | set |
---|---|
Needs documentation: | set |
Needs tests: | set |
Patch needs improvement: | set |
comment:11 by , 10 years ago
About the documentation for this PR: I think we should make options.label
and options.label_lower
public API.
comment:12 by , 10 years ago
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 by , 10 years ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
comment:14 by , 10 years ago
Patch needs improvement: | unset |
---|
comment:15 by , 10 years ago
Cc: | added |
---|
comment:16 by , 10 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Yes please!