Not really. Each model "belongs to" ("is defined in") a single
application. All that means (and exactly what it means) is that the
model's "app_name" is that application's name and there are a few cases
(e.g. default database table) where we use <app_name> + <model_name> to
generate identifiers.
However, you might be approaching this the wrong way. Any application
can import models from any other application. So if you want to split
out certain pieces of business logic or presentation logic into other
applications -- which isn't necessarily a bad thing -- then put those
items into one app and they can import the models from the models'
originating app.
Now, as for putting the models into separate files: that's possible and
it has to be under the models/ directory in one of your apps. The only
thing to know here is that you must then set the "app_name" attribute on
the inner Meta class for each model to be the name of the app directory.
For example, with this structure:
myapp1/
models/
component.py
...
any model in component.py will have to say something like
class Component(models.Model):
...
class Meta:
app_name = 'myapp1'
So "app_name" is just the application's directory name (*just* that
directory name, nothing with dots in it or anything like that).
Hope that gives you some ideas.
Regards,
Malcolm
>
> Thank you
>
> >
> So for now there is only this models_app which should contain the
> models. When I try to run syncdb, models under models/ are not imported.
> Is there any magic to do into models_app/models/__init__.py ?
There is no magic in the models. You just need to make sure you added
models_app
to your INSTALLED_APPS directive in the settings.py.
syncdb only install models from installed apps.
Regards
adi
> So for now there is only this models_app which should contain the
> models. When I try to run syncdb, models under models/ are not
> imported. Is there any magic to do into
> models_app/models/__init__.py ?
You need to import them into the models/ namespace, because Django only
looks in <app_name>.models for any model definitions. So your
__init__.py will be a bunch of imports from your subfiles (with
judicious use of __all__ in the subfiles, it's just going to be a list
of "from component import *" sort of lines).
Regards,
Malcolm