Reputation: 12605
I have a Django application that exposes RESTful APIs built with the Django-Rest-Framework.
My APIs are all custom APIs. IE, I don't use ModelSerializers
.
Here is what my serializer looks like:
class MySerializer(serializers.Serializer):
my_email = serializers.EmailField()
my_string = serializers.CharField()
my_integer = serializers.IntegerField()
But I would like to modify this serializer and the (associated view) such that there is a new parameter that takes a list of integers. How do I implement lists/arrays/collections through Django-Rest-Framework? I have been unable to find any answers in the documentation or by Googling.
Upvotes: 0
Views: 2207
Reputation: 2630
According to the django rest framework documentation:
http://www.django-rest-framework.org/api-guide/fields
on the Third party packages
section, DRF Compound Fields does the job, you can find more info here: https://github.com/estebistec/drf-compound-fields
but in this case would be:
from drf_compound_fields.fields import ListField
class MySerializer(serializers.Serializer):
...
my_list_of_integers = ListField(serializers.IntegerField())
regards
Upvotes: 1