Re: ignore field during form validation

2013-01-23 Thread Sarfraz ahmad
def clean_A6M1F6_F(self):
data=self.cleaned_data['A6M1F6_F']
if A6M1_mobile.objects.filter(A6M1F6=data).exists():
 raise forms.ValidationError(" already exixts")
return data
i have this clean_field method in the form and given field is not
updatable... whenever i tried to update the record with the form having
initial data as the record already inserted in the database this method
raise an exception while calling the is_valid() method



On Tue, Jan 22, 2013 at 7:39 PM, Sarfraz ahmad wrote:

> gusy i have form which has 5 fields i have defined a clean_field
> method which doesn't allow a duplicate entry in the database.
> bt when i tried to update the model instance while calling form.is_valid()
> method it calls the clean_field() method and returns error that entry
> already exists.
>
>
>
> On Tue, Jan 22, 2013 at 2:57 AM, Mario Gudelj wrote:
>
>> Add required=False to the form field and it won't be validated.
>> On 22 Jan, 2013 2:30 AM, "Jonathan D. Baker" <
>> jonathandavidba...@gmail.com> wrote:
>>
>>>  Hi Sarfraz,
>>>
>>> If your form class inherits from ModelForm, you can use a subset of
>>> fields within your form per the following documentation:
>>> https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form
>>>
>>> If you're not inheriting from ModelForm, then it's a matter of
>>> configuring your model and form fields to allow null/blank. In this case,
>>> seeing your code would help provide more direction.
>>>
>>> Hope this helps,
>>> Jonathan
>>>
>>> On 01/21/2013 04:34 AM, Sarfraz ahmad wrote:
>>>
>>> Hello everyone,
>>>
>>>  i m facing a problem while validating django
>>> form. i have 5 form fields in a form and in the view i want to
>>> validate only three form fields which i need to update .. tell me a
>>> solution if anyone have any
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msg/django-users/-/oZfMAZ8FWt4J.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>>
>>>
>>> --
>>> Software Developerhttps://github.com/jondbaker
>>> GPG: 1F6F3FFD
>>>
>>>  --
>>> 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
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>  --
>> 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
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: ignore field during form validation

2013-01-22 Thread Sarfraz ahmad
gusy i have form which has 5 fields i have defined a clean_field method
which doesn't allow a duplicate entry in the database.
bt when i tried to update the model instance while calling form.is_valid()
method it calls the clean_field() method and returns error that entry
already exists.


On Tue, Jan 22, 2013 at 2:57 AM, Mario Gudelj wrote:

> Add required=False to the form field and it won't be validated.
> On 22 Jan, 2013 2:30 AM, "Jonathan D. Baker" 
> wrote:
>
>>  Hi Sarfraz,
>>
>> If your form class inherits from ModelForm, you can use a subset of
>> fields within your form per the following documentation:
>> https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form
>>
>> If you're not inheriting from ModelForm, then it's a matter of
>> configuring your model and form fields to allow null/blank. In this case,
>> seeing your code would help provide more direction.
>>
>> Hope this helps,
>> Jonathan
>>
>> On 01/21/2013 04:34 AM, Sarfraz ahmad wrote:
>>
>> Hello everyone,
>>
>>  i m facing a problem while validating django
>> form. i have 5 form fields in a form and in the view i want to
>> validate only three form fields which i need to update .. tell me a
>> solution if anyone have any
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/django-users/-/oZfMAZ8FWt4J.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>>
>> --
>> Software Developerhttps://github.com/jondbaker
>> GPG: 1F6F3FFD
>>
>>  --
>> 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
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>  --
> 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
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: ignore field during form validation

2013-01-21 Thread Mario Gudelj
Add required=False to the form field and it won't be validated.
On 22 Jan, 2013 2:30 AM, "Jonathan D. Baker" 
wrote:

>  Hi Sarfraz,
>
> If your form class inherits from ModelForm, you can use a subset of fields
> within your form per the following documentation:
> https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form
>
> If you're not inheriting from ModelForm, then it's a matter of configuring
> your model and form fields to allow null/blank. In this case, seeing your
> code would help provide more direction.
>
> Hope this helps,
> Jonathan
>
> On 01/21/2013 04:34 AM, Sarfraz ahmad wrote:
>
> Hello everyone,
>
>  i m facing a problem while validating django
> form. i have 5 form fields in a form and in the view i want to
> validate only three form fields which i need to update .. tell me a
> solution if anyone have any
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/oZfMAZ8FWt4J.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>
> --
> Software Developerhttps://github.com/jondbaker
> GPG: 1F6F3FFD
>
>  --
> 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
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: ignore field during form validation

2013-01-21 Thread Jonathan D. Baker
Hi Sarfraz,

If your form class inherits from ModelForm, you can use a subset of
fields within your form per the following documentation:
https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form

If you're not inheriting from ModelForm, then it's a matter of
configuring your model and form fields to allow null/blank. In this
case, seeing your code would help provide more direction.

Hope this helps,
Jonathan

On 01/21/2013 04:34 AM, Sarfraz ahmad wrote:
> Hello everyone,
>
>  i m facing a problem while validating django
> form. i have 5 form fields in a form and in the view i want to
> validate only three form fields which i need to update .. tell
> me a solution if anyone have any
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/oZfMAZ8FWt4J.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.


-- 
Software Developer
https://github.com/jondbaker
GPG: 1F6F3FFD

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: ignore field during form validation

2013-01-21 Thread Sarfraz ahmad
Hello everyone,

 i m facing a problem while validating django form. 
i have 5 form fields in a form and in the view i want to validate only 
three form fields which i need to update .. tell me a solution if 
anyone have any

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/oZfMAZ8FWt4J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: ignore field during form validation

2012-07-27 Thread Karen Tracey
On Thu, Jul 26, 2012 at 11:14 AM, Zoltan Szalai wrote:

> Hi all,
>
> Let's assume i have to the following simple form:
>
>
> class Form(forms.Form):
>
> check = forms.BooleanField(
> required=False,
> )
> # take into account only when 'check' is True
> len = forms.IntegerField(
> min_value=3,
> max_value=5,
> required=True,
> )
>
>
> What I want is to validate the 'len' field only when 'check' is True.
> I could define the clean method of the form and validate the required,
> min_value and max_value stuff only when 'check' is True but the case when
> someone types a non integer value into the input is still there. How could
> I skip that? That check is done by the IntegerField.
>

You could use two different Django forms, and only call is_valid() on the
one with the len value if the first one with the check value indicates that
check is True. Both of these Django forms can be rendered in a single HTML
. I think that approach is a little cleaner than inspecting the POST
data yourself.

Karen
-- 
http://tracey.org/kmt/

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: ignore field during form validation

2012-07-26 Thread Zoltan Szalai
In the end I came up with a solution which seems a bit hacky but does 
exactly what I want.

It looks like this:

def clean(self):
cleaned_data = super(Form, self).clean()
check = cleaned_data.get("check", None)

# ignore 'len' when 'check' is False
if not checkand "len" in self._errors:
del self._errors["len"]

return cleaned_data


one thing to note: "len" won't be available in cleaned_data but that's 
just cool since it's not valid :)



On 2012.07.26. 18:29, Kurtis Mullins wrote:
You could remove "required=True" from 'len' and override clean() to 
perform a multiple-field validation. (pretty much what Thomas mentioned)


len() will execute -- it will check to see if it's an integer. If you 
just want to completely ignore it, then do exactly as Thomas said, 
override. But you'll have to make sure you do the "Integer Validation" 
check in your clean() method if you ignore that validation in clean_len().


clean__len():
return self.cleaned_data['len']

On Thu, Jul 26, 2012 at 12:21 PM, Zoltan Szalai > wrote:


On 2012.07.26. 17 :44, Tomas Neme wrote:

class Form(forms.Form):

 check = forms.BooleanField(
 required=False,
 )
 # take into account only when 'check' is True
 len = forms.IntegerField(
 min_value=3,
 max_value=5,
 required=True,
 )


What I want is to validate the 'len' field only when
'check' is True.
I could define the clean method of the form and validate
the required,
min_value and max_value stuff only when 'check' is True
but the case when
someone types a non integer value into the input is still
there. How could I
skip that? That check is done by the IntegerField.

well, you could override clean_len() and not do anything in
it, and
then override clean() and do your check there.


I don't think that would help. The clean method of the Field
(IntegerField in this case) would still run.



--
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: ignore field during form validation

2012-07-26 Thread Kurtis Mullins
You could remove "required=True" from 'len' and override clean() to perform
a multiple-field validation. (pretty much what Thomas mentioned)

len() will execute -- it will check to see if it's an integer. If you just
want to completely ignore it, then do exactly as Thomas said, override. But
you'll have to make sure you do the "Integer Validation" check in your
clean() method if you ignore that validation in clean_len().

clean__len():
return self.cleaned_data['len']

On Thu, Jul 26, 2012 at 12:21 PM, Zoltan Szalai wrote:

> On 2012.07.26. 17:44, Tomas Neme wrote:
>
>> class Form(forms.Form):
>>>
>>>  check = forms.BooleanField(
>>>  required=False,
>>>  )
>>>  # take into account only when 'check' is True
>>>  len = forms.IntegerField(
>>>  min_value=3,
>>>  max_value=5,
>>>  required=True,
>>>  )
>>>
>>>
>>> What I want is to validate the 'len' field only when 'check' is True.
>>> I could define the clean method of the form and validate the required,
>>> min_value and max_value stuff only when 'check' is True but the case when
>>> someone types a non integer value into the input is still there. How
>>> could I
>>> skip that? That check is done by the IntegerField.
>>>
>> well, you could override clean_len() and not do anything in it, and
>> then override clean() and do your check there.
>>
>>
> I don't think that would help. The clean method of the Field (IntegerField
> in this case) would still run.
>
>
>
>
> --
> 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 django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en
> .
>
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: ignore field during form validation

2012-07-26 Thread Zoltan Szalai

On 2012.07.26. 17:44, Tomas Neme wrote:

class Form(forms.Form):

 check = forms.BooleanField(
 required=False,
 )
 # take into account only when 'check' is True
 len = forms.IntegerField(
 min_value=3,
 max_value=5,
 required=True,
 )


What I want is to validate the 'len' field only when 'check' is True.
I could define the clean method of the form and validate the required,
min_value and max_value stuff only when 'check' is True but the case when
someone types a non integer value into the input is still there. How could I
skip that? That check is done by the IntegerField.

well, you could override clean_len() and not do anything in it, and
then override clean() and do your check there.



I don't think that would help. The clean method of the Field 
(IntegerField in this case) would still run.




--
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: ignore field during form validation

2012-07-26 Thread Tomas Neme
> class Form(forms.Form):
>
> check = forms.BooleanField(
> required=False,
> )
> # take into account only when 'check' is True
> len = forms.IntegerField(
> min_value=3,
> max_value=5,
> required=True,
> )
>
>
> What I want is to validate the 'len' field only when 'check' is True.
> I could define the clean method of the form and validate the required,
> min_value and max_value stuff only when 'check' is True but the case when
> someone types a non integer value into the input is still there. How could I
> skip that? That check is done by the IntegerField.

well, you could override clean_len() and not do anything in it, and
then override clean() and do your check there.

The only problem is that you won't be able to raise the issue as a
field-specific error

-- 
"The whole of Japan is pure invention. There is no such country, there
are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.