def annotate_channel_queryset_with_latest_activity_at(queryset, user):
return queryset.annotate(
latest_activity_timestamp=Max('action_targets__timestamp'),
).annotate(
latest_activity_at=Case(
When(
latest_activity_timestamp__isnull=True,
then='created_at'
),
When(
latest_activity_timestamp__gt=F('created_at'),
then='latest_activity_timestamp'
),
default='created_at',
output_field=DateTimeField()
)
)
评论列表
文章目录