0

I'm making a vote app (Django rest framework), where users can post content and have it voted on through two options. The Vote modelVote model code has a ForeignKey field to the Post model, with the related name attribute "votes". The vote model also has a field named 'option', where choices 'option1' and 'option2' can be selected.

My goal is to count the total number of votes on a post, number of option1 votes and number of option2 votes.

I've been able to count the number of votes on a post through:

queryset = Post.objects.annotate(
        votes_count=Count('votes', distinct=True),       
    )

Post views

I am unsure how to count the number of option1 and option2 votes, separately.

0 Answers0