Using DjangoModels without a server running

Subscribe to Using DjangoModels without a server running 1 post, 1 voice

 
Avatar mikele 11 post(s)

Dear all,
I need to import some xml into my webapp (called ltb1) – it’s a one-off thing so I want to do it outside
the webapp, but still making use of all the models I’ve defined in it..
So I created a new package in my djangostack/projects/ltb1 which contains a new module ‘import_xml’.
I should be able to access the DB through the django models, so to parse the xml and feed the results
into the DB accordingly.
(Essentially, I wanted to manually load whatever usually gets loaded with ‘manage.py’):


import sys, os,  ltb1.settings
from django.core.management import setup_environ
setup_environ(ltb1.settings)

from ltb1.ltbapp.models import MyModel

It seems to work till the ‘setup_env….’ but then it fails when I try to import my models. Here’s the result:


Traceback (most recent call last):
  File "/Applications/djangostack-1.0-6/projects/ltb1/src/ltb1_xml/test.py", line 6, in <module>
    from ltb1.ltbapp.models import EndnoteReferences
  File "/Applications/djangostack-1.0-6/projects/ltb1/src/python_ltb1/../python_ltb1/ltbapp/models.py", line 1, in <module>
  File "/Applications/djangostack-1.0-6/apps/django/lib/python2.5/site-packages/django/db/__init__.py", line 16, in <module>
    backend = __import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {}, {}, [''])
  File "/Applications/djangostack-1.0-6/apps/django/lib/python2.5/site-packages/django/db/backends/mysql/base.py", line 13, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/mac/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.4-i386.egg-tmp/_mysql.so, 2): Library not loaded: /usr/local/mysql/lib/libmysqlclient_r.15.dylib
  Referenced from: /Users/mac/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.4-i386.egg-tmp/_mysql.so
  Reason: image not found

I must have NOT included some other setting that loads the right python_mysql bridge, I guess…
any suggestion?

tx!