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 Aymeric Augustin

Yes please!

comment:2 Changed 7 years ago by Markus Holtermann

+1

comment:3 Changed 7 years ago by John Giannelos

Owner: changed from nobody to John Giannelos
Status: newassigned

comment:4 Changed 7 years ago by Tim Graham

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 Baptiste Mispelon

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 Markus Holtermann

Cc: Markus Holtermann added

options.app_label is never converted to lower case.

comment:7 Changed 7 years ago by Baptiste Mispelon

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

comment:8 Changed 7 years ago by Luis Del Giudice

Owner: changed from John Giannelos to Luis Del Giudice

comment:9 Changed 7 years ago by Luis Del Giudice

comment:10 Changed 7 years ago by Markus Holtermann

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

comment:11 Changed 7 years ago by Markus Holtermann

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 Luis Del Giudice

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 Tim Graham

Needs documentation: unset
Needs tests: unset

comment:14 Changed 7 years ago by Luis Del Giudice

Patch needs improvement: unset

comment:15 Changed 7 years ago by Alasdair Nicol

Cc: alasdair@… added

comment:16 Changed 7 years ago by Markus Holtermann

Triage Stage: AcceptedReady for checkin

comment:17 Changed 7 years ago by Markus Holtermann <info@…>

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