I am using Django 3.0.4 with Django REST Framework 3.11.0 where I have a models.py like:
from django.db import models
from model_utils.models import TimeStampedModel
class SampleModel(TimeStampedModel):
class Options(models.TextChoices):
FOO = "A"
BAR = "B"
BAZ = "C"
name = models.CharField(default="", max_length=512)
options = models.CharField(
max_length=2,
choices=Options.choices,
default=Options.FOO
)
I would like to be able to create an API endpoint to return a list of my TextChoices as a tuple. I have a React frontend where I want to create a <select> dropdown with my list of choices. If I can access the list of TextChoices via an API endpoint, I should be good to go.
path("api/sample/choices/", views.SampleChoicesListView.as_view(), name="sample_choices")
I'm not sure what my views.py needs to look like to make this work...
class SampleChoicesListView(generics.ListAPIView):
pass

