def validate_email_unique(email, for_user=None):
 existing_accounts = get_user_model().objects.filter(email=email)
 existing_email = EmailAddress.objects.filter(email=email)
 if (for_user is not None):
  existing_accounts = existing_accounts.exclude(pk=for_user.pk)
  existing_email = existing_email.exclude(user=for_user)
 if (existing_accounts.exists() or existing_email.exists()):
  raise ValidationError('A user with that email address already exists')

def validate_email_unique ( email , for_user = None ) : existing_accounts = get_user_model ( ) . objects . filter ( email = email ) existing_email = EmailAddress . objects . filter ( email = email ) if ( for_user is not None ) : existing_accounts = existing_accounts . exclude ( pk = for_user . pk ) existing_email = existing_email . exclude ( user = for_user ) if ( existing_accounts . exists ( ) or existing_email . exists ( ) ) : raise ValidationError ( 'A user with that email address already exists' )
validates an email to ensure it does not already exist in the system .