Hi ! I have an application that splits models into different files.
Actually the folder looks like :
>myapp
__init__.py
models.py
>hooks
...
...
myapp
don't care about what's in the hooks
, folder, except that there are models, and that they have to be imported somehow, and installed by syncdb. So, I put this in myapp.__init__.py
:
from django.conf import settings
for hook in settings.HOOKS :
try :
__import__(hook)
except ImportError as e :
print "Got import err !", e
#where settings.HOOKS = ("myapp.hooks.a_super_hook1", ...)
In order for this code to work, the models in hooks
have
class Meta:
app_label="my_app"
The problem is that it doesn't work when I run syncdb
.
So I tried successively :
1)
for hook in settings.HOOKS :
try :
exec ("from %s import *" % hook)
-> doesn't work either : syncdb doesn't install the models in hooks
2)
from myapp.hooks.a_super_hook1 import *
-> This works
3)
exec("from myapp.hooks.a_super_hook1 import *")
-> This works to
So I checked that in the test 1), the statement executed is the same than in tests 2) and 3), and it is exactly the same ...
Any idea ???
EDIT : The question could be summarized to :
I declared models outside of "models.py", where to put MY import code, so that syncdb
finds the models ?