views:

61

answers:

1

Is it possible to import models from apps in different Django projects?

I hope to move some common models in a base projects from which every child projects can share the same data in these common models.

Edit

I have to place

from baseproject.appname.models import basemodel

before

os.environ['DJANGO_SETTINGS_MODULE'] = 'childproject.settings'
from django.conf import settings

in child project to access the data in base model correctly.

+1  A: 

Yes. You can turn a project-specific app into a standard Python package by moving it to site-packages (or wherever your Python install expects its modules) and breaking any links from it to other apps in the project. You can then import it as you would any Python module, in any project.

Ignacio Vazquez-Abrams
Hi Ignacia, the base project is already installed site-packages folder. The import statement "from baseproject.app.models import basemodel" works but when I tried to access data in basemodel, it keep showing "Table childproject.baseproject_basemodel doesn't exists".
jack
It's not necessary to put the whole project in site-packages, just the app. Did you remember to add it to `INSTALLED_APPS` and do a syncdb?
Ignacio Vazquez-Abrams
@Ignacio, I just found the reason.
jack