D
D
Dmitry Vyatkin2015-08-27 17:21:40
Django
Dmitry Vyatkin, 2015-08-27 17:21:40

How to check form field value for specific values?

Good afternoon!
I check in forms.py the validity of the values ​​entered by the user.

class chooses_log(forms.Form):
    channel = forms.CharField(required=True,  min_length=3, max_length=10)
    date    = forms.DateField(input_formats=['%Y/%m/%d'])
    page    = forms.IntegerField(required=True, min_value=1, max_value=1000)

In the channel field, there are three options that the user can choose from. How to check these values? Can this be done without validators?
To make it clearer, a user on the site clicks on a link, let's say support, the GET parameter channel=support comes to the view, we create a variable with the form, pass GET parameters to it and then check the validity of form.is_valid(), and so, as in the channel field check that the value matches 'support' or two other values. otherwise return False.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kir Marchenko, 2015-08-27
@dim137

return channel if channel in ['support', 'second', 'third'] else False
?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question