Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
using model classes without a server
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
xamdam  
View profile  
 More options Feb 19 2006, 1:15 pm
From: "xamdam" <maxkhe...@gmail.com>
Date: Sun, 19 Feb 2006 18:15:29 -0000
Local: Sun, Feb 19 2006 1:15 pm
Subject: using model classes without a server
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?

thanks,
max.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Twomey  
View profile  
(1 user)  More options Feb 19 2006, 1:36 pm
From: Michael Twomey <micktwo...@gmail.com>
Date: Sun, 19 Feb 2006 18:36:36 +0000
Local: Sun, Feb 19 2006 1:36 pm
Subject: Re: using model classes without a server
On 19/02/06, xamdam <maxkhe...@gmail.com> 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

cheers,
  Michael


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
xamdam  
View profile  
 More options Feb 19 2006, 1:42 pm
From: "xamdam" <maxkhe...@gmail.com>
Date: Sun, 19 Feb 2006 18:42:09 -0000
Local: Sun, Feb 19 2006 1:42 pm
Subject: Re: using model classes without a server
Nice, thanks!

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Szakmeister  
View profile  
 More options Feb 20 2006, 6:40 am
From: John Szakmeister <j...@szakmeister.net>
Date: Mon, 20 Feb 2006 06:40:18 -0500
Local: Mon, Feb 20 2006 6:40 am
Subject: Re: using model classes without a server
On Sunday 19 February 2006 13:36, Michael Twomey wrote:

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Twomey  
View profile  
 More options Feb 20 2006, 7:07 am
From: Michael Twomey <micktwo...@gmail.com>
Date: Mon, 20 Feb 2006 12:07:41 +0000
Local: Mon, Feb 20 2006 7:07 am
Subject: Re: using model classes without a server
On 20/02/06, John Szakmeister <j...@szakmeister.net> wrote:

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

This is true, I've encountered this as well. You do get basic database
level validation of your queries which will catch the big sillies, but
I think the validation happens using the manipulators. Just trying it
now I've gotten some mileage with this:

>>> from django.models.auth import users
>>> manipulator = users.AddManipulator()
>>> manipulator.get_validation_errors(dict(username="mtt",

first_name="Michael", last_name="Twomey", email="mtt"))
{'date_joined_date': ['This field is required.'],
 'date_joined_time': ['This field is required.'],
 'email': ['Enter a valid e-mail address.'],
 'last_login_date': ['This field is required.'],
 'last_login_time': ['This field is required.'],
 'password': ['This field is required.'],
  'username': ['User with this username already exists.']}

What would be nice is some kind of validate flag for save or the class
constructor which raised an exception with this info in it. This would
make life a little easier for scripting.

Another thing missing is logic to construct the slugs, they currently
come from the admin javascript AFAIK.

cheers,
  Michael


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adrian Holovaty  
View profile  
 More options Feb 23 2006, 10:40 am
From: "Adrian Holovaty" <holov...@gmail.com>
Date: Thu, 23 Feb 2006 09:40:57 -0600
Local: Thurs, Feb 23 2006 10:40 am
Subject: Re: using model classes without a server
On 2/20/06, Michael Twomey <micktwo...@gmail.com> wrote:

That's exactly what we're discussing in the "validation-aware models" thread. :)

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Twomey  
View profile  
 More options Feb 25 2006, 9:03 am
From: Michael Twomey <micktwo...@gmail.com>
Date: Sat, 25 Feb 2006 08:03:13 -0600
Local: Sat, Feb 25 2006 9:03 am
Subject: Re: using model classes without a server
On 23/02/06, Adrian Holovaty <holov...@gmail.com> wrote:

> That's exactly what we're discussing in the "validation-aware models" thread. :)

Ack, now I see that thread :)

thanks,
  Michael


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google