On Nov 23, 2007 9:42 AM, Wolfram Kriesing <[EMAIL PROTECTED]> wrote:
>
> On Nov 23, 2007 3:28 PM, James Bennett <[EMAIL PROTECTED]> wrote:
> >
> > On 11/23/07, Wolfram Kriesing <[EMAIL PROTECTED]> wrote:
> > > looks cleaner in my eyes. opinions please!
> >
> > In my opinion, you're asking for a lot of custom behavior from a
> > default field type, and the fact that you have to do some custom
> > coding to support that custom behavior is not a bug ;)
> >
>
> I wouldn't call it a bug either but adding flexibility, which makes
> the newforms cleaning+validation just easier to grasp. Currently
> clean() does validation too, which I didn't expect it to from the
> beginning, simply because it's name doens't suggests it.
> Is the case I mentioned so very special? I think that forms are often
> enough that complex that one field's value depends on another fields
> value.
>
> What is the main reason for not making all the cleaned_data available
> in the clean_<field>() method? (Doing that would be the quickest
> solution without breaking BC and adding a hell lot more flexibility)
>
> Wolfram

You can access self.cleaned_data to use any data which has already
been cleaned - since fields are stored in a SortedDict, this means you
can access the cleaned data from any field defined prior to the field
you're writing a custom clean_* method for within that method. In your
case, you could use something like this if you were to use a CharField
for your url field:

def clean_url(self):
    if self.cleaned_data['type'] == 'url':
        return forms.URLField().clean(self.cleaned_data['url'])
    return self.cleaned_data['url']

Jonathan.

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

Reply via email to