V
V
Vladimir2018-07-04 14:39:49
Django
Vladimir, 2018-07-04 14:39:49

How to display field error in Wagtail admin?

There is a model and it has a clean method. During validation, it can throw an error like ValidationError({'amount': _('Transaction results in a negative balance')})
But Wagtail, as I understand it, will catch this error as non_fields_errors, and according to his design visions, it is displayed as a simple 'Unable to create Voucher transaction due to errors.' without indicating the field with the specifics of the error.
Has anyone faced this? Whether it is possible to solve it with small losses?
Thanks for the help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Сергей Тихонов, 2018-07-08
@FonVald

У Django-форм есть методы clean_"fieldname", которые проверяют корректность отдельных полей. Метод clean проверяет как эти поля друг с другом сочитаются, поэтому ошибки из него и формируются как non_field_errors (т.е. сами значения корректные - февраль, 31 число - но вместе не сочитаются).
Можно попробовать бросить ValidationError в методе clean_amount.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question