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 *This field is required.*? 
I can't see another wat to raise a  default error message like required, 
blank, invalid, unique_together without pass the message again.


def clean():  
    cleaned_data = super().clean()
    password = cleaned_data.get('password')
    password_confirm = cleaned_data.get('password_confirm')

    if password and not password_confirm:
        # Raise the required validation error (with default message  'This 
field is required')
        self.fail('password_confirm', 'required')
   
    return cleaned_data

The example problem is a password confirmation, but can be any type of 
field that can be required based on another field

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/46b4fa99-c060-4ba2-9bc2-9ef3b6a822bc%40googlegroups.com.

Reply via email to