Opened 14 years ago

Closed 11 years ago

Last modified 10 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@… 14 years ago.
14007_model_package_automatic_discovery.diff (8.1 KB ) - added by Aram Dulyan 13 years ago.
Cleanly-applying version of the patch above.
14007_fix_with_docs.diff (9.1 KB ) - added by Aram Dulyan 13 years ago.
The above patch with appropriate documentation changes.

Download all attachments as: .zip

Change History (15)

comment:1 by pandres, 13 years ago

Owner: changed from nobody to pandres

comment:2 by pandres, 13 years ago

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).

by Aram Dulyan, 13 years ago

Cleanly-applying version of the patch above.

comment:3 by Aram Dulyan, 13 years ago

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.

by Aram Dulyan, 13 years ago

Attachment: 14007_fix_with_docs.diff added

The above patch with appropriate documentation changes.

comment:4 by Aram Dulyan, 13 years ago

Needs documentation: unset

comment:5 by patchhammer, 13 years ago

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 by Julien Phalip, 13 years ago

Type: UncategorizedNew feature

comment:7 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

comment:8 by aav, 12 years ago

Cc: aav added
UI/UX: unset

comment:9 by Edwin <django@…>, 11 years ago

Cc: django@… added

comment:10 by Tim Graham, 11 years ago

Cc: timograham@… added
Patch needs improvement: unset

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

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

#2982 and #4470 were duplicates.

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