Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ArrayField in serializer

Im my model, one of my filed are ArrayField. How can I use this field in serializer class.

class MyModel(models.Model):
    arr = ArrayField(models.CharField())


class MySerializer(ModelSerializer):
    class Meta:
        model = MyModel
        fields = ('arr')
like image 238
Mohammad Ali Avatar asked Sep 04 '18 05:09

Mohammad Ali


1 Answers

use ListField with child argument

class MySerializer(ModelSerializer):
    arr = serializers.ListField(child=serializers.CharField())

    class Meta:
        model = MyModel
        fields = ('arr',)
like image 117
JPG Avatar answered Oct 20 '22 19:10

JPG