1 from rest_framework import serializers
3 class ChoiceField(serializers.CharField):
4 def __init__(self, *args, **kwargs):
6 self._choices = kwargs.pop('choices', sentinel)
7 if self._choices is sentinel:
8 raise Exception('Choices is required')
10 self._choices = set(self._choices)
11 super().__init__(self, *args, **kwargs)
13 def to_internal_value(self, data):
14 if data not in choices:
15 raise serializers.ValidationError('{} not in choices {}'.format(
21 class FollowRedirectsSerializer(serializers.Serializer):
22 link = serializers.URLField(required=True)
23 remove_utm = serializers.BooleanField(required=False)
24 handler = serializers.ChoiceField(
25 choices=['display', 'redirect'],