I'd recommend not using a custom field for this. Instead, you can do 
something like:

class ExerciseForm(forms.Form):
        exercise_field = forms.CharField(widget=forms.TextInput(attrs={
'autocomplete': 'off', 'autofocus': 'autofocus'}))

        def __init__(self, *args, **kwargs):
            self.language = kwargs.pop('language', None)
            self.dictionary = kwargs.pop('dictionary', None)
            self.exercise_text = self.getRandomText(self.language, self.
dictionary)
            super(ExerciseForm, self).__init__(*args, **kwargs)

        def clean_exercise_field(self):
            if self.cleaned_data['exercise_field'] != self.exercise_text:
                raise forms.ValidationError("Texts don't match")
            return self.cleaned_data['exercise_field']

https://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-a-specific-field-attribute

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8270d4a0-6d8d-4b6c-bceb-337080fda535%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to