Answer the question
In order to leave comments, you need to log in
Why doesn't Django's clean() pass validation in tests?
I have a model and a method in it
def clean(self):
# проверка на совпадение входной и выходной валюты
if self.ccy == self.base_ccy:
raise ValidationError(_('course.model.clean.unique'))
# проверка на обратное направления
if Course.objects.filter(ccy=self.base_ccy, base_ccy=self.ccy):
raise ValidationError(_('course.model.clean.reunique'))
# проверка на добавление обекта с одинаковым направлением
with self.assertRaises(ValidationError):
Course.objects.create(ccy=self.course_1.base_ccy, base_ccy=self.course_1.base_ccy)
Answer the question
In order to leave comments, you need to log in
From documentation :
Note, however, that like Model.full_clean(), a model's clean() method is not invoked when you call your model's save() method.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question