I am implementing Django REST API framework using the 'rest_serializer' module:
Currently the output is:
{
"count": 86,
"next": "http://127.0.0.1:8000/state/?page=2",
"previous": null,
"results": [
{
"state_name": "Alaska"
},
{
"state_name": "California"
},
...
]
}
How do I display just this as a json list:
[
"Alaska",
"California",
...
]
Below are my serializers:
from .models import States
from rest_framework import serializers
class StateSerializer(serializers.ModelSerializer):
class Meta:
model = State
fields = ('state_name',)
view.py
class StateViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows groups to be viewed or edited.
"""
queryset = States.objects.values('state_name').distinct();
serializer_class = StateSerializer
you cam override
list
method, provided by listmodelmixin: