Horje
how to count post by category django Code Example
how to count post by category django
#views.py
from django.db.models import Count
# You should change post in Count function based on your model.
categories = Category.objects.all().annotate(posts_count=Count('post'))

#Then you will have access to number of posts for each category:
for category in categories:
    print(category.posts_count)

#in your template
{% for category in categories %}
      <p>Number of posts: {{category.posts_count}}</p>
{% endfor %}




Python

Related
pprint(ASingleReview) TypeError: 'module' object is not callable Code Example pprint(ASingleReview) TypeError: 'module' object is not callable Code Example
counter in django template Code Example counter in django template Code Example
Mean Kurtosis of all rows pandas Code Example Mean Kurtosis of all rows pandas Code Example
how to say hello with name in python Code Example how to say hello with name in python Code Example
compute mfcc python Code Example compute mfcc python Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
6