You have to understand that what you are doing is chaining filters.
First you had a queryset with annotated votes count likeannotate(votos_ok=Count('votomoderacion')).filter(votomoderacion__voto="1")
.
Then you annotated votes_ok
with it and filterered it like annotate(votos_ok=Count('votomoderacion')).filter(votomoderacion__voto="1")
, which gave you another filtered queryset.
But after that, you added another filter annotate(votos_no_ok=Count('votomoderacion')).filter(votomoderacion__voto="0")
, which filtered the queryset which you got from previous filter. so, in this case, you didn't get your desired result.
So better if you separate them. Like:
total_votes= Vine.objects.annotate(votos_count=Count('votomoderacion'))
yes_votes= Vine.objects.annotate(votos_ok=Count('votomoderacion')).filter(votomoderacion__voto="1")
no_votes= Vine.objects.annotate(votos_no_ok=Count('votomoderacion')).filter(votomoderacion__voto="0")
To join those queryset:
from itertools import chain
allvotes = list(chain(total_votes, yes_votes, no_votes))