django apps and models.py in 1.7 - what exactly has changed? -
django 1.7 has introduced apparently major changes how apps work
https://docs.djangoproject.com/en/dev/releases/1.7/#app-loading-refactor
these release notes seem saying can define models outside of models.py
, don't need models.py
(or models/__init__.py
) inside app.
am misunderstanding this? if not, explain define our models if not in models.py
, how django find , load them?
you should still define models in models.py
.
before app refactor in 1.7 there wasn't unified api declaring metadata app. in particular, way django determined whether app or not looking models.py
file. not elegant system, when consider apps don't have models (for example, app might provide management commands).
now appconfig
api exists it's no longer necessary require existence of models.py
. however, it's still natural, , default, place define models.
how django find , load them?
from documentation: "you must define or import models in application’s models.py
or models/__init__.py
."
that suggests following practice: if don't have models, don't include models.py
. if have file's worth of models, put them in models.py
. if have bunch of models , want spread them out on multiple files, put files in models
submodule , import contents in models/__init__.py
.
Comments
Post a Comment