Validation checks the number entered by the user is between the range
and this check is done in "def clean_guess_the_number".  This is not
working.

Seems like "def clean_guess_the_number(self)" never executed when you
post the data and when form.is_valid() called.

class GuessForm(forms.Form):

    guess_the_number= forms.RegexField(r'^\d+$',
                                max_length = 10,
                                min_length = 1,
                                error_message = 'Must be 1-10 numeric
characters.'
                                )

    def __init__(self, *args, **kwargs):
        try:
            self.id = kwargs.pop('id')

        except:
            pass

        super(GuessForm, self).__init__(*args, **kwargs)

        number = get_object_or_404(Number,
                                pk=self.id
                                )

        increment = Increment.objects.all()
        self.max_number = number.value + increment[0].value
        self.min_number = number.value + increment[1].value

    def clean_guess_the_number(self):
        if self.max_number > self.cleaned_data['guess_the_number']:
            raise forms.ValidationError('Your Number have to be lower
or equal to Max Number.')
        if self.min_number < self.cleaned_data['guess_the_number']:
            raise forms.ValidationError('Your Number have to be higer
or equal to Min Number.')
        return self.cleaned_data['guess_the_number']

html:
<p>
    <label for="id_guess_the_number">Guess The Number( Number must be
between {{form.min_number}} and {{form.max_number}}):</label>
{{ form.guess_the_number }}
    {% if form.guess_the_number.errors %}***
{{ form.guess_the_number.errors|join:", " }}{% endif %}
</p>


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