This is the models.py
class CompetitionEntry(models.Model):
submitter = models.ForeignKey(User)
pic = models.ImageField(upload_to=images, blank=True, null=True)
class CompetitionEntryVote(models.Model):
voted_entry = models.ForeignKey(CompetitionEntry)
class Entrylikes(models.Model):
ip_address = models.IPAddressField()
liked_entry = models.ForeignKey(CompetitionEntry)
This is the views.py (i think problem is here)
def show_all_entries(request, id):
entries = CompetitionEntry.objects.filter(competition__id__exact=comp.id).annotate(vote_count=Count('competitionentryvote'), likes_count=Count('entrylikes'))
return render(request, "show_all.html", {
"entries": entries,
})
show_all.html
{% for item in entries %}
Votes = {{item.vote_count}} Likes= {{item.likes_count}}
{% endfor %}
The problem here is that Both the votes and likes are same in the output. i,e votes=likes = likes
and if i rewrite views to show only one of either votes or likes , the page works perfectly.
and in views.py if i used
entries = CompetitionEntry.objects.filter(competition__id__exact=comp.id).annotate(vote_count=Count('competitionentryvote')).annotate(likes_count=Count('entrylikes'))I get the same result as 1 above