34👍
✅
Your syntax mistake is here,
Feed.objects.filter(user=self.request.user)
.annotate(Count('piece', filter=Q(piece__removed=False)))
filter needs to apply at Count
not at annotate
.
Reference from Django’s documentation:
https://docs.djangoproject.com/en/2.1/topics/db/aggregation/#filtering-on-annotations
Source:stackexchange.com