#25127: document how to define models in multiple modules
-------------------------------+--------------------
Reporter: keturn | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
Though recent versions of Django have taken steps to support the ability
have a number of models organized in a `models/` package instead of a
single `models.py` file, the Models documentation topic does not give
guidance on how to do this.
Searching the web for answers turns up a lot of 2009-era results, which I
believe are misleading when applied to current versions of Django.
There is a [https://code.djangoproject.com/wiki/CookBookSplitModelsToFiles
cookbook entry] which looks at least halfway current.
Statements I've seen (which I think are now questionable) are:
* If your models are not in `models.py`, you have to explicitly set
`db_table` on each model.
* ...you have to explicitly set `app_label` on each model
* in `models.py` or `models/__init__.py` you have to `import *` from each
module where you define models
There's this statement in the
[https://docs.djangoproject.com/en/1.7/releases/1.7/#app-loading-refactor
Django 1.7 release notes]:
> Application labels are assigned correctly to models even when they’re
defined outside of models.py. You don’t have to set app_label explicitly
any more.
which makes me think all of those things may be obsolete. Are there any
constraints on where you define models now? If they're not in `models.py`,
what do you need to do to ensure they're loaded?
Documentation on the
[https://docs.djangoproject.com/en/dev/ref/applications/#initialization-
process app initilaization process] still says the app's `models` module
or package is loaded, so maybe that "you must `import *` in your
`models.py` or `models/__init__.py`" thing is still true?
--
Ticket URL: <https://code.djangoproject.com/ticket/25127>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.fdd771986bcafaede964ee6700be2e9e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.