[Fixed]-Django – 'WhereNode' object has no attribute 'output_field' error

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

Leave a comment