Trying to get the total count of objects with a bool value of true to display on the template Here's what I have so far models.py

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>

Screenshot 2022-04-17 193334

It doesn’t work, where do i go from here?

You should become more familiar with how the Class-Based views work, and how you integrate with them. In addition to the docs, I recommend both the Classy ClassBased View site along with the CBV diagrams page to understand how they work. (Your “total” function isn’t doing anything - it not even going to be called.)

Briefly, you’ll be overriding the get_context_data method of the view class to add this data to the context to be rendered.