-
Notifications
You must be signed in to change notification settings - Fork 296
Open
Description
Is it possible to express this:
class Item(Model):
name = TextField()
@unique
class Color(Enum):
Red = "red"
Green = "green"
Blue = "blue"
class ItemSerializer(ModelSerializer):
color = SerializerMethodField()
def get_color(self, instance) -> Color:
return Color.Red.value
class Meta:
model = Item
fields = "__all__"
We've been able to use Enum
s directly within Model
s, using https://github.com/akx/django-enumfields2 and that translates properly into an OpenAPI enum
.
Is there a way to expose similar functionality through a SerializerMethod
in a way drf-spectacular
can process?
Metadata
Metadata
Assignees
Labels
No labels