Re: Create a shortcut for raising ValidationError from within the Form.clean() method

2019-09-09 Thread Adam Johnson
Hi Lucas, In the case that you want to apply an error to a specific field, there's the add_error method (docs: https://docs.djangoproject.com/en/2.2/ref/forms/api/#django.forms.Form.add_error ). For your example (untested): def clean(self): cleaned_data = super().clean() password = clea

Re: Create a shortcut for raising ValidationError from within the Form.clean() method

2019-09-06 Thread Lucas Weyne
Hi Adam, Your refactor works great and thats how I was thinking to solve this problem. My idea its was use the Meta.error_messages dictionary to solve default error messages. What if I want to raise a ValidationError for a conditional required field and display the default required message *T

Re: Create a shortcut for raising ValidationError from within the Form.clean() method

2019-09-06 Thread Adam Johnson
Hi Lucas, Thank you for writing to the list with your proposal. At first glance, I'm not sure of the value. Shortcuts are nice but they come at the expense of there being two ways to do things. Your example might not best express your idea, but if I were to refactor it to what Django currently s

Create a shortcut for raising ValidationError from within the Form.clean() method

2019-09-06 Thread Lucas Weyne
I want to create a shortcut method to raise ValidationError inside the Form.clean() method. When we need to raise the same ValidationError (same message and same code) many times inside the Form.clean(), I should pass the same message every time. Would be cleaner, pass only the error code and