On Sunday 19 February 2006 13:36, Michael Twomey wrote:
> On 19/02/06, xamdam <[EMAIL PROTECTED]> wrote:
> > Django models can already be manipulated outside of the web app with
> > manage.py shell
> > I am looking for a way to have a regular python script (say, running a
> > batch job) use the model classes. It seems like I just have to import
> > the right stuff (which 'shell' option does automagically), but I
> > haven't figure out what. Suggestions?
>
> Hi,
>
> You need to do two things, setup the settings module and then import the
> models:
>
> # You can also set DJANGO_SETTINGS_MODULE in your shell
> import os
> os.environ["DJANGO_SETTINGS_MODULE"] = "myproject.settings"
>
> import django.conf.settings
> from django.models.myapp import articles

One thing that I've found, at least on Django's trunk code, is that if you do 
this, validation doesn't take place when you do model.save().  I tried 
setting up a couple of fields as "required if other fields is present", and 
it happily saved the model without enforcing it.  I've also found that it 
doesn't enforce the blank=False attribute either.  I'm sure it's something 
I'm doing wrong, but just doing things the intuitive way (load the model, 
create/modify it, and then saving it) allowed me to insert data that didn't 
conform to the restrictions I had placed on the model.

-John

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@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-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to