I
I
Ilya2016-02-28 00:58:09
Django
Ilya, 2016-02-28 00:58:09

How to correctly get the number of posts in a category?

Can you tell me how to display the number of posts for a category?
I am making a list of categories, and I want each one to have a number with the number of posts in it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2016-02-28
@nuBacuk

stackoverflow.com/questions/3395863/how-can-i-get-...

class Book(models.Model):
    section = models.ForeignKey(Section, related_name="books")

{{ sec.books.count }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question