Serializing One Field From A ManyToManyField DRF
I have been lot of posts, the DRF documentation (which needs LOT of love), and I couldn't find yet how to do this without a complicated mess. I need this output: [{'id':1,'name':'m
Solution 1:
You just need a SlugRelatedField
:
class CheckSerializer(serializers.ModelSerializer):
subscribers = serializers.SlugRelatedField(many=True, read_only=True, slug_field='name')
class Meta:
model = Check
fields = ('id', 'name', 'subscribers')
Post a Comment for "Serializing One Field From A ManyToManyField DRF"