title: Use the Django ORM in a standalone script (again)
body: <p>I'm trying to use the Django ORM in some standalone screen scraping scripts. I know this question has been asked before, but I'm unable to figure out a good solution for my particular problem.</p>
  
  <p>I have a Django project with defined models. What I would like to do is use these models and the ORM in my scraping script. My directory structure is something like this:</p>
  
  <pre><code>project
      scrape
          #scraping scripts
          ...
          test.py
      web
          django_project
              settings.py
              ...
              #Django files
  </code></pre>
  
  <p>I tried doing the following in <code>project/scrape/test.py</code>:</p>
  
  <pre><code>print os.path.join(os.path.abspath('..'), 'web', 'django_project')
  sys.path.append(os.path.join(os.path.abspath('..'), 'web', 'django_project'))
  print sys.path
  print "-------"
  os.environ['DJANGO_SETTINGS_MODULE'] = 'django_project.settings'
  #print os.environ
  from django_project.myapp.models import MyModel
  print MyModel.objects.count()
  </code></pre>
  
  <p>However, I get an <code>ImportError</code> when I try to run test.py:</p>
  
  <pre><code>Traceback (most recent call last):
    File "test.py", line 12, in &lt;module&gt;
      from django_project.myapp.models import MyModel
  ImportError: No module named django_project.myapp.models
  </code></pre>
  
  <p>One solution I found around this problem is to create a symbolic link to <code>../web/govcheck</code> in the scrape folder:</p>
  
  <pre><code>:scrape rmanocha$ ln -s ../web/govcheck ./govcheck
  </code></pre>
  
  <p>With this, I can then run test.py just fine. However, this seems like a hack, and more importantly, is not very portable (I will have to create this symbolic link everywhere I run this code).</p>
  
  <p>So, I was wondering if anyone has any better solutions for my problem?</p>