Re: Using Django Models outside of Django

2007-05-16 Thread Grigoriy Petukhov

johnny wrote:
> Doing the following:
> 
> from os import environ
> environ['DJANGO_SETTINGS_MODULE'] = 'settings'
> from settings import *
> 
> Only works at the parent folder level.  What if you have script in sub
> folder level?  I tried it at sub folder level and got error:
> 
> from os import environ
> environ['DJANGO_SETTINGS_MODULE'] = '../settings'
> from settings import *
 from apps.mail.models import Email
> Traceback (most recent call last):
>   File "", line 1, in ?
> ImportError: No module named apps.mail.models
> 
> 
> > 
> 

import os
# "keeno.ru" directory contains my project directory "web_site"
sys.path.append('/web/keeno.ru')
os.environ["DJANGO_SETTINGS_MODULE"] = 'web_site.settings'

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



Re: Using Django Models outside of Django

2007-05-15 Thread Malcolm Tredinnick

On Tue, 2007-05-15 at 15:18 -0700, johnny wrote:
> Doing the following:
> 
> from os import environ
> environ['DJANGO_SETTINGS_MODULE'] = 'settings'
> from settings import *
> 
> Only works at the parent folder level.  What if you have script in sub
> folder level?  I tried it at sub folder level and got error:
> 
> from os import environ
> environ['DJANGO_SETTINGS_MODULE'] = '../settings'

This has to be a Python import path, not a file path. So the settings
file needs to be somewhere on your Python path. It always works when it
is in the current directory, because the current directory is always
implicitly on your Python path.

Regards,
Malcolm




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



Re: Using Django Models outside of Django

2007-05-15 Thread johnny

Doing the following:

from os import environ
environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from settings import *

Only works at the parent folder level.  What if you have script in sub
folder level?  I tried it at sub folder level and got error:

from os import environ
environ['DJANGO_SETTINGS_MODULE'] = '../settings'
from settings import *
>>> from apps.mail.models import Email
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named apps.mail.models
>>>


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



Re: Using Django Models outside of Django

2007-05-08 Thread Joseph Heck

Generally outside and prior to any thread initiation should be fine.

-joe

On 5/8/07, johnny <[EMAIL PROTECTED]> wrote:
>
> Since I have my code in threaded manner, do I have to put the
> following code inside threaded function or outside?
>
> from os import environ
> environ['DJANGO_SETTINGS_MODULE'] = 'settings'
>
> from settings import *
>
>
> >
>

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



Re: Using Django Models outside of Django

2007-05-08 Thread johnny

Since I have my code in threaded manner, do I have to put the
following code inside threaded function or outside?

from os import environ
environ['DJANGO_SETTINGS_MODULE'] = 'settings'

from settings import *


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



Re: Using Django Models outside of Django

2007-05-07 Thread jeffhg58
I think this documentation will provide what you are looking for

http://code.djangoproject.com/wiki/InitialSQLDataDiangoORMWay

jeff

-- Original message -- 
From: johnny <[EMAIL PROTECTED]> 

> 
> I have a python script that runs in a multi threaded manner for 
> backend to update certain flags in the table. I want to use django 
> models to do this. I was wondering if I import the django models just 
> like any other python, would that work? 
> 
> Also, what about the database connection, can I just create a database 
> connection inside the python script and use Django Models? 
> 
> 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Using Django Models outside of Django

2007-05-07 Thread James Bennett

On 5/7/07, johnny <[EMAIL PROTECTED]> wrote:
> I have a python script that runs in a multi threaded manner for
> backend to update certain flags in the table.  I want to use django
> models to do this.  I was wondering if I import the django models just
> like any other python, would that work?

You will need to either set the environment variable
DJANGO_SETTINGS_MODULE to point at a Django settings file, or use
manual configuration in your application to set up necessary
configuration like the database type, name and auth info. See the
documentation for details:

http://www.djangoproject.com/documentation/settings/#using-settings-without-setting-django-settings-module

> Also, what about the database connection, can I just create a database
> connection inside the python script and use Django Models?

Django will handle its own database connection automatically, based on
the settings you specify.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

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



Using Django Models outside of Django

2007-05-07 Thread johnny

I have a python script that runs in a multi threaded manner for
backend to update certain flags in the table.  I want to use django
models to do this.  I was wondering if I import the django models just
like any other python, would that work?

Also, what about the database connection, can I just create a database
connection inside the python script and use Django Models?

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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---