Trying to get the total count of objects with a bool value of true or false to display on the template
Here’s what I have so far
models.py
class Issue(models.Model):
MARK_AS = ((True, 'Open'), (False, 'Closed'))
title = models.CharField(max_length=100)
content = models.TextField()
date_posted = models.DateTimeField(default=timezone.now)
author = models.ForeignKey(User, on_delete=models.CASCADE)
assignee = models.ForeignKey(Profile, on_delete=models.SET_NULL, null=True, blank=True)
mark_as = models.BooleanField(choices=MARK_AS, default=True)
views.py
class IssueListView(ListView):
model = Issue
template_name = 'issues/home.html'
context_object_name = 'issues'
ordering = ['-date_posted']
paginate_by = 5
def total():
open_issues = Issue.objects.filter(mark_as=True).count()
closed_issues = Issue.objects.filter(mark_as=False).count()
context = {
'open_issues': open_issues,
'closed_issues': closed_issues}
return context
template
<ul class="topics__list">
<li>
<a href="" class="active">All <span>{{ page_obj.paginator.count }}</span></a>
</li>
<li>
<a href="">Open<span>{{issues.open_issues}}</span></a>
</li>
<li>
<a href="">Closed<span>{{issues.closed_issues}}</span></a>
</li>
</ul>
It doesn’t work, where do i go from here?