class PostSerializer(serializers.ModelSerializer):
user = serializers.PrimaryKeyRelatedField(queryset=User.objects.all())
class Meta:
model = Post
fields = ('id', 'user', 'comment')
username = serializers.SerializerMethodField("get_username")
def get_username(self, obj):
return obj.owner.username