This is useful if subclassing the views and using custom serializers.
Use case: User Signups is restricted to administrator users only. I set up a custom SignupSerializer that needs to validate the email address to make sure the domain matches the current user - the current user needs to be found from request.user
E.g.:
def email_domain(email):
# return email domain of 'email' - example.com
class EmailSignupSerializer(SignupSerializer):
def validate_email(self, value):
if email_domain(value) != email_domain(self.context['request'].user.email):
raise serializers.ValidationError("You may only add users with from the same email domain as yours')
return value
This is useful if subclassing the views and using custom serializers.
Use case: User Signups is restricted to administrator users only. I set up a custom SignupSerializer that needs to validate the email address to make sure the domain matches the current user - the current user needs to be found from request.user
E.g.: