from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers


class EnumField(serializers.ChoiceField):
    default_error_messages = {
        "invalid_choice": _('"{input}" is not a valid choice.')
    }

    def __init__(self, enum, **kwargs):
        self.enum = enum
        choices = (
            (self.get_value(enum_value), enum_value.label)
            for _, enum_value in enum.choices()
        )
        super().__init__(choices, **kwargs)

    def get_value(self, enum_value):
        return enum_value.value

    def to_internal_value(self, data):
        if isinstance(data, str) and data.isdigit():
            data = int(data)

        try:
            value = self.enum.get(data).value
        except AttributeError:
            if not self.required:
                raise serializers.SkipField()
            self.fail("invalid_choice", input=data)

        return value

    def to_representation(self, value):
        enum_value = self.enum.get(value)
        if enum_value:
            return self.get_value(enum_value)


class NamedEnumField(EnumField):

    def get_value(self, enum_value):
        return enum_value.name

@@ -333,32 +333,39 @@
       (self.get_
+choice_
 value(enum_value
@@ -492,32 +492,39 @@
 s)%0A%0A    def get_
+choice_
 value(self, enum
@@ -1061,24 +1061,31 @@
 rn self.get_
+choice_
 value(enum_v
@@ -1138,16 +1138,23 @@
 def get_
+choice_
 value(se

Rename choice value method