On Fri, Jul 4, 2008 at 11:26 AM, Malcolm Tredinnick < [EMAIL PROTECTED]> wrote:
> > > On Fri, 2008-07-04 at 11:08 +0200, Alex Rades wrote: > > Hi, > > I have a project with 3 application which could (should) share their > > models. Morover, I'd like to put models into a separate directory, > > splitted into multiple files. Something like: > > > > myproject/ > > models/ > > box.py > > firmware.py > > component.py > > myapp1/ > > myapp2/ > > myapp3/ > > > > Is it possible to organize the project in this way? > > 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. > Hi Malcom, My 3 applications have all the same level of relation with the models so I'd rather prefer not to privilege one of them as the main app/models owner. Anyway, I could create an application whose only function is models container, I can live with this :) As for the models splitting, I've tried the approach you suggested, but it doesn't work yet. My project structure is the following |-- models_app | |-- models | | |-- __init__.py | | |-- backend.py | | |-- box.py | | `-- release.py | `-- __init__.py |-- __init__.py |-- app.db |-- manage.py |-- settings.py `-- urls.py 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 received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---