V
V
Vitaly Ananiev2022-01-12 19:11:22
Django
Vitaly Ananiev, 2022-01-12 19:11:22

What needs to be written in order to get an error, it's not a number?

forms.py

def clean(self):
        price = self.cleaned_data['price']
        availability = self.cleaned_data['availability']
        if price < 1:
            raise ValidationError('Цена не может быть ниже 1')
        elif availability < 1:
            raise ValidationError('Количество не должно быть ниже 1')
        elif price != int: - вот здесь в условии что нужно прописать 
            raise ValidationError('Это не число!') -

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2022-01-12
@bacon

Just start reading the docs already, huh? https://docs.djangoproject.com/en/4.0/ref/forms/fi...

T
Tynay Bakasov, 2022-01-12
@Yobanaris

Maybe just prohibit the use of letters and make a field purely for numbers?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question