def validate_username(self, value):
try:<EOL><INDENT>user = User.objects.get(username=value)<EOL><DEDENT>except User.DoesNotExist:<EOL><INDENT>raise serializers.ValidationError("<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>enterprise_customer_user = models.EnterpriseCustomerUser.objects.get(user_id=user.pk)<EOL><DEDENT>except models.EnterpriseCustomerUser.DoesNotExist:<EOL><INDENT>raise serializers.ValidationError("<STR_LIT>")<EOL><DEDENT>self.enterprise_customer_user = enterprise_customer_user<EOL>return value<EOL>
Verify that the username has a matching user, and that the user has an associated EnterpriseCustomerUser.