I have a model with custom "ArrayField" (for a Postgres array field), which stores an array of foreign keys to another model. Django doesn't enforce the relation, but what I put in there are foreign keys.
class Foo(model):
bars = ArrayField(models.IntegerField())
class Bar(model):
blah = models.CharField()
So the value of the 'bars' field is like [3,64,7,34,...] where the numbers are non-enforced foreign keys to Bar. When rendering Foos, I'd like to render the related objects represented in this field using Django REST Framework:
{ "foo" : { "bars" : [ {"blah":"asdf"},
{"blah":"asdf"}
]
}
}
I'm having trouble figuring out how that should be expressed in the serializer:
class BarSerializer(serializers.ModelSerializer):
class Meta:
fields = ('blah')
blah = serializersCharField()
class FooSerializer(serializers.ModelSerializer):
class Meta:
fields = ('bars')
# bars = BarSerializer(many=True)
bars = SomeSpecialCustomField() #?
How can I get JSON as above when rendering?