Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
conditional model validation
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
  3 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
 
Lachlan Musicman  
View profile  
 More options Sep 27 2012, 7:29 pm
From: Lachlan Musicman <data...@gmail.com>
Date: Fri, 28 Sep 2012 11:26:01 +1200
Local: Thurs, Sep 27 2012 7:26 pm
Subject: conditional model validation
Hola,

I'm searching without much luck and can't see the answer in the docs.

Am wanting to override the is_valid() method on a model (I think
that's what I want).

Basically, I have a choices field, and if one of those choices is
selected, then I want a description field to be not blank/not the
empty string. If it's the other two choices, I want the description
field to be blank/empty string.

First, I override is_valid() as a model method?

Second, how do I return a false from is_valid()?

ie, this is a rough up of what I'm looking for - what goes in place of
return FALSE/TRUE?

def is_valid(self):

if enrolment.mark == 'W': #student has withdrawn from course
-if enrolment.withdrawal_reason == '': #must have reason
--return FALSE
elif enrolment.withdrawal.reason != "": #ie, since enrolment.mark
isn't 'W', confirm that the enrolment.reason is ""
-return FALSE
else:
-return TRUE

Cheers
L.
--
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314


 
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.
Babatunde Akinyanmi  
View profile  
 More options Sep 28 2012, 2:37 am
From: Babatunde Akinyanmi <tundeba...@gmail.com>
Date: Fri, 28 Sep 2012 07:36:18 +0100
Local: Fri, Sep 28 2012 2:36 am
Subject: Re: conditional model validation
Let me try to assist. A forms is_valid method causes 3 types of
cleaning methods to be run. Based on that, I'm sure you really don't
need to override it.

I really don't understand what you mean by "I want the description
field to be not blank/not the empty string" so maybe I could have been
of more help but I'm sure a solution to your problem would be to
override either the form's clean_fieldname or clean methods.

Check: https://docs.djangoproject.com/en/dev/ref/forms/validation/
which is a link to the documentation on form validation

On 9/28/12, Lachlan Musicman <data...@gmail.com> wrote:

--
Sent from my mobile device

 
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.
Lachlan Musicman  
View profile  
 More options Sep 28 2012, 8:14 pm
From: Lachlan Musicman <data...@gmail.com>
Date: Sat, 29 Sep 2012 12:13:55 +1200
Local: Fri, Sep 28 2012 8:13 pm
Subject: Re: conditional model validation

On Friday, September 28, 2012, Babatunde Akinyanmi wrote:
> Let me try to assist. A forms is_valid method causes 3 types of
> cleaning methods to be run. Based on that, I'm sure you really don't
> need to override it.

Yes, I've just discoverde the ValidationError e part of the docs :|

> I really don't understand what you mean by "I want the description
> field to be not blank/not the empty string" so maybe I could have been
> of more help but I'm sure a solution to your problem would be to
> override either the form's clean_fieldname or clean methods.

ie,
if e.mark = W, e.descr must be >"" # it can be anything from "a" to
"pregnant" to "killed" to "this is not an empty string" or " this is not a
blank string"
else e.descr == "" #this is a blank or empty string

> Check: https://docs.djangoproject.com/en/dev/ref/forms/validation/
> which is a link to the documentation on form validation

cheers - since I am using the admin forms, I was hoping I could add it to
the model, but is ok if I need to rewrite the forms

cheers
L.

--
...we look at the present day through a rear-view mirror. This is something
Marshall McLuhan said back in the Sixties, when the world was in the grip
of authentic-seeming future narratives. He said, “We look at the present
through a rear-view mirror. We march backwards into the future.”

http://www.warrenellis.com/?p=14314


 
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 »