[patch] Allow models to live outside models.py
|Reported by:||Luke Plant||Owned by:||Adrian Holovaty|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
In current magic-removal, you get exceptions if you want to place a model outside of the models.py module (e.g. in a subpackage) (to be specific, the check that the model is in INSTALLED_APPS throws an exception). The attached patch fixes this by allowing 'module' to be specified as a 'Meta' option.
Previously using 'app_label' would fix it. By specifying 'module' instead, you won't need 'app_label' (in the usual case at least). Meta.module should be the fully qualified module name of the models file e.g. 'myproj.myapp.models', and you also need to import your model classes into
It looks like this:
class Foo(models.Model): # fields etc class Meta: module = 'myapp.myproj.models'
from some_random_file import Foo
I think that's relatively clean. It only requires one line extra per model than what you would usually do i.e. the 'module' option in 'Meta'.