2👍
✅
class RelationshipSerializer(serializers.ModelSerializer):
user = UserSerializer(read_only=True)
related_user = UserSerializer(read_only=True)
class Meta:
model = models.Relationship
fields = (
'user',
'related_user',
'relationship'
)
user = UserSerializer(read_only=True, many=True)
is for manytomany field,user = UserSerializer(read_only=True)
is for ForeignKey field.
👤Ykh
Source:stackexchange.com