most_viewed_videos = Video.objects.filter(
videowatch__created__month=today.month,
viewing__status="D"
).annotate(
count=Count("videowatch"),
viewing_count=Sum("viewing")
).values("count", "viewing_count").order_by(
"-viewing_count",
"-count"
)
嘿,我有这个代码片段,我的问题是如何将count
and 加viewing_count
在一起得到一个结果。
我试过了,但我没有找到任何有效的方法。
编辑:解决方案对我有用
most_viewed_videos = Video.objects.filter( videowatch__created__month=today.month, viewing__status="D" ).extra( select={'total': 'COUNT("videowatch") + SUM(CAST("viewing" as CHAR))'} ).values("total").order_by("-total")