Opened 6 years ago

Closed 3 years ago

Last modified 3 years ago

#14007 closed New feature (fixed)

Automatically discover models within a package without using the app_label Meta attribute

Reported by: mark@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Normal Keywords: sprintdec2010 package models model
Cc: aav, django@…, timograham@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Automatically figure out the app_label for a model by looking one level up from the package or module named 'models'.
If no such package or module exists, fall back to the behavior of looking one level up from
the module the model is defined in.

For 'django.contrib.sites.models', this would be 'sites'.
For 'geo.models.places' this would be 'geo'.
For 'polymorphic.polymorhpic_model' this would be 'polymorphic'.

This allows organization of models within a package named 'models' without having to specify the app_label Meta attribute for each model.

Attachments (3)

model_package_automatic_discovery.diff (7.0 KB) - added by mark@… 6 years ago.
14007_model_package_automatic_discovery.diff (8.1 KB) - added by Aramgutang 6 years ago.
Cleanly-applying version of the patch above.
14007_fix_with_docs.diff (9.1 KB) - added by Aramgutang 6 years ago.
The above patch with appropriate documentation changes.

Download all attachments as: .zip

Change History (15)

Changed 6 years ago by mark@…

comment:1 Changed 6 years ago by pandres

Needs documentation: unset
Needs tests: unset
Owner: changed from nobody to pandres
Patch needs improvement: unset

comment:2 Changed 6 years ago by pandres

Needs documentation: set
Owner: changed from pandres to nobody
Patch needs improvement: set

Please upload a new patch fixing the title of the files.

A bug in Trac makes it difficult to see which file the patches belong (try -A1 -B1 and double check the file names).

Changed 6 years ago by Aramgutang

Cleanly-applying version of the patch above.

comment:3 Changed 6 years ago by Aramgutang

Keywords: sprintdec2010 added
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

The tests for the entire suite pass with the patch. The functionality works as advertised.

I've also tested it every which way I could think of, including plugging it into a giant project that uses models modules extensively and does some advanced customisation of the admin, and it still works.

Changed 6 years ago by Aramgutang

Attachment: 14007_fix_with_docs.diff added

The above patch with appropriate documentation changes.

comment:4 Changed 6 years ago by Aramgutang

Needs documentation: unset

comment:5 Changed 5 years ago by patchhammer

Easy pickings: unset
Patch needs improvement: set
Severity: Normal
Type: Uncategorized

14007_fix_with_docs.diff fails to apply cleanly on to trunk

comment:6 Changed 5 years ago by Julien Phalip

Type: UncategorizedNew feature

comment:7 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

comment:8 Changed 5 years ago by aav

Cc: aav added
UI/UX: unset

comment:9 Changed 3 years ago by Edwin <django@…>

Cc: django@… added

comment:10 Changed 3 years ago by Tim Graham

Cc: timograham@… added
Patch needs improvement: unset

comment:11 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 2333c9662b5ffbaec5a10fa2973b4e6e7b0555bd:

Fixed #14007 -- Added model discovery in models module without the need to specify app_label.

Thanks mark@ and Aramgutang for work on the patch.

comment:12 Changed 3 years ago by Aymeric Augustin

#2982 and #4470 were duplicates.

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