DRF and PostgreSQL: ArrayField is returned as an array of chars

Viewed 37

I have a Contact model with a field like this:

#models.py

address = ArrayField(models.CharField(max_length=255, null=True), default=list)

This stores an array of email addresses. I'm creating an api and wanted this to be returned as an array of email addresses as strings but I get an array of chars instead (as in the screenshot). Can someone hint me what to do?

My serializer:

class ContactSerializer(serializers.ModelSerializer):
    class Meta:
        model = Contact
        fields = '__all__'

Output: output

EDIT: Example address from a db record: enter image description here

EDIT 2: This is how the value looked like in pandas DataFrame just before being stored in db: enter image description here

1 Answers

Have you tried using ListField?

class ContactSerializer(serializers.ModelSerializer):
    class Meta:
        model = Contact
        fields = '__all__'

    address = serializers.ListField(child=serializers.CharField())
Related