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 Aymeric Augustin, 10 years ago

Yes please!

comment:2 by Markus Holtermann, 10 years ago

+1

comment:3 by John Giannelos, 10 years ago

Owner: changed from nobody to John Giannelos
Status: newassigned

comment:4 by Tim Graham, 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 Baptiste Mispelon, 10 years ago

What's the advantage of doing options.label_lower rather than options.label.lower()?

Or are these two different things?

comment:6 by Markus Holtermann, 10 years ago

Cc: Markus Holtermann added

options.app_label is never converted to lower case.

comment:7 by Baptiste Mispelon, 10 years ago

Ah yes, that makes sense. Sorry for the noise :)

comment:8 by Luis Del Giudice, 10 years ago

Owner: changed from John Giannelos to Luis Del Giudice

comment:9 by Luis Del Giudice, 10 years ago

comment:10 by Markus Holtermann, 10 years ago

Has patch: set
Needs documentation: set
Needs tests: set
Patch needs improvement: set

comment:11 by Markus Holtermann, 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 Luis Del Giudice, 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 Tim Graham, 10 years ago

Needs documentation: unset
Needs tests: unset

comment:14 by Luis Del Giudice, 10 years ago

Patch needs improvement: unset

comment:15 by Alasdair Nicol, 10 years ago

Cc: alasdair@… added

comment:16 by Markus Holtermann, 10 years ago

Triage Stage: AcceptedReady for checkin

comment:17 by Markus Holtermann <info@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 69ddc1b:

Fixed #24693 -- Added label and label_lower property to Model._meta

Note: See TracTickets for help on using tickets.
Back to Top