You need your external program to do several things:

1) make sure django is on your PYTHONPATH (or within the Python
script, on sys.path)
2) make sure your apps are also on the PYTHONPATH (or sys.path)
3) set the DJANGO_SETTINGS_MODULE environment variable in your shell
or script

Then you just import the same way you would in Django itself:

from appname.models import MyModel




On Aug 20, 3:03 pm, clochemer <cloche...@gmail.com> wrote:
> Hi everyone!
>
> It's my first question, and that's because I am totally lost. I am not
> a great Django developer (neither a good Python programmer) so I do
> not even know if I am doing the right things, let me explain...
>
> I have an external Python program which reads from a socket and
> depending on what it receives, it inserts some new models in Django
> database. All clear right here?
>
> Let's go on... I said myself "Hey genius, you only have to import the
> models and that's all!". So I made a new folder on my project path
> called utils, so I have something like... /home/myproject/utils/
> communicator.py, where my fantastic program is located.
>
> But as all of you might have already seen, i don't know how to import
> models form there.
>
> I had a problem similar, as i defined some Python functions which deal
> with models and are used in several Django applications, but i solved
> it by locating those functions in /usr/lib/python2.6/site-packages/
> django/contrib/myproject and the import worked. I guess the problem is
> in a Python/Django paths misunderstanding of mine.
>
> I need some wisdom & guidance,
>
> Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to