python - "No module named" Error When Importing Django Models Outside the Django App -


i have repo containing django app, , scripts need various things database that's behind app. ideally, i'd love use django orm edits , updates database, since django leaves me pretty ugly mysql table names (my_app_sometablename). doing through orm nice consistency reasons, , other reasons orm exists in first place.

anyway, i'm having lot of difficulty importing django models outside of app. i've tried editing pythonpath, , i've tried importing 50 different ways, , still no dice. structure like:

repo/    __init__.py    django_app/       __init__.py       sub1a/          __init__.py          models.py    scripts/       __init__.py       some_script.py 

i'm trying do:

from django_app.sub1a.models import somemodel 

i can part work, if add path repo python path, when try use imported doing like:

res = somemodel.objects.filter(**kwargs) 

i get:

  ...   file "/path/to/.virtualenvs/repo/lib/python2.7/site-packages/django/db/models/loading.py", line 64, in _populate     self.load_app(app_name, true)   file "/path/to/.virtualenvs/analyticsv2/lib/python2.7/site-packages/django/db/models/loading.py", line 86, in load_app     app_module = import_module(app_name)   file "/path/to/.virtualenvs/analyticsv2/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module     __import__(name) importerror: no module named sub1a 

what doing wrong? how fix it? driving me nuts.

you own django admin commands performs tasks need.

https://docs.djangoproject.com/en/dev/howto/custom-management-commands/#howto-custom-management-commands


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -