On 4/17/06, Julio César Carrascal Urquijo <[EMAIL PROTECTED]> wrote:
> I would like to use django models on external scripts to
> initialize/modify the database. Is it possible?

It certainly should be possible.

> I've followed the instructions of the tutorial (set
> DJANGO_SETTINGS_MODULE='website.settings' and importing
> website.settings works on python shell) but haven't been able to get it
> to work with this simple script:
>
> from models import Format
> [f.save() for f in (
>         Format(order= 1, name='One'),
>         Format(order= 2, name='Two'),
> )]

Ok; first off - have you been able to run the development server
successfully with your project? Have you used the admin view to
create/delete/modify "Format" objects?

> Executing "initialize.py" on the command line always shows the error:
> EnvironmentError: Could not import settings ''website.settings'' (is it
> on sys.path?): No module named 'website.settings'. (Yes, it is on
> sys.path).

This sounds like you haven't set up DJANGO_SETTINGS_MODULE properly.
To check this - If you start a Python prompt (not the manage.py shell
- just a normal Python shell), what gets printed when you run:

>>> import os
>>> print os.environ['DJANGO_SETTINGS_MODULE']

?

If you get a KeyError, then whatever you are doing to set
DJANGO_SETTINGS_MODULE isn't working when you start the script. Since
you are using Windows - how are you starting the script?

> and if I try to import the script under manage.py shell it shows:
> AttributeError: 'Format' object has no attribute 'id'.

Nothing immediately jumps to the front of my mind - however, your
import statement is a little wierd - ordinarily, I would expect to see
"from project.app.models import Format"

Where is your 'initialize.py' script located?

Where/how are you executing it?

What exactly is output when you run:

>>> import sys
>>> print sys.path

?

At the manage.py shell, does "from models import Format" raise any exceptions?

At the manage.py shell, does "from project.app.models import Format"
(for appropriate values of project.app) raise any exceptions?

Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to