Since Django 1.4 the syntax to import you models in external scripts has changed. The setup_environ method has been deprecated for a while and it no longer exists in Django 1.6.

Assuming you’re using a virtualenv and your script is one directory outside the main Django project directory structure.

my_directory/ | |---> virtualenv/ |---> my_project/ my_script.py

I use this for Django 1.6 integration in my_script.py:

sys.path.append(os.path.join(os.path.dirname(__file__), ‘my_project’))

os.environ.setdefault(“DJANGO_SETTINGS_MODULE”, “my_project.settings”)

from django.conf import settings

from my_app.models import MyModel

Share this: Twitter

Facebook

LinkedIn

Reddit

Pinterest

More

Email

Tumblr



