def channel_new_messages_annotation(user):
"""
Queryset needs to annotated with channel_last_read for this to work
:param user:
:return:
"""
return Sum(
Case(
When(
~Q(action_targets__actor_object_id=user.id) &
Q(action_targets__gt=F('channel_last_read')) &
Q(action_targets__verb__in=[verbs.SEND, verbs.UPLOAD]),
then=1
),
default=0,
output_field=IntegerField()
)
)
评论列表
文章目录