答案 0 :(得分:0)
您需要在序列化程序中使用SerializerMethodField
。
class Serializer(serializers.ModelSerializer):
field_name = serializers.SerializerMethodField()
class Meta:
model = Model
def get_field_name(self, obj):
return obj.field_or_method_name
http://www.django-rest-framework.org/api-guide/fields/#serializermethodfield