【发布时间】:2014-08-05 16:55:47
【问题描述】:
似乎找不到合适的谷歌搜索,所以这里是:
我的序列化程序中有一个字段:
likescount = serializers.IntegerField(source='post.count', read_only=True)
计算所有相关字段“post”。
现在我想将该字段用作我的方法的一部分:
def popularity(self, obj):
like = self.likescount
time = datetime.datetime.now()
return like/time
这可能吗?
【问题讨论】:
-
第二种方法从何而来? (
popularity),那么你想在哪里访问数据? -
就在序列化程序类中,其中“likescount”在@DenisCornehl中
标签: python django django-rest-framework