title: Django counting one to many relationship
body: <p>So i have two tables, <strong><em>Post</em></strong> and <strong><em>Category</em></strong></p>
  
  <p>Code:</p>
  
  <p>model.py</p>
  
  <pre><code>class Category(models.Model):
       category = models.CharField(max_length=100)
  
       def __str__(self):
           return self.category
  </code></pre>
  
  <hr>
  
  <pre><code>class Post(models.Model):
       title = models.CharField(max_length=200)
       author = models.CharField(max_length=40)
       category = models.ForeignKey(Category)
       content = models.TextField()
       created_date = models.DateTimeField(default=timezone.now)
  
       class Meta:
           ordering = ['-created_date']
  
       def __str__(self):
           return self.title + ' - ' + str(self.created_date.date())
  </code></pre>
  
  <p>And I want to implement category list in template. For example I have few categories</p>
  
  <p>Sports(2) <code>2-number of how many posts are within sports category</code></p>
  
  <p>template code:</p>
  
  <pre><code>&lt;h3&gt;Categories&lt;/h3&gt;
      &lt;ul class="nav navbar-stacked"&gt;
          {% for category in categories %}
              &lt;li&gt;&lt;a href="#"&gt;{{ category }}&lt;span class="pull-right"&gt;(
                  {{ **post.category.count** }}
              )&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
          {% endfor %}
      &lt;/ul&gt;
  </code></pre>
  
  <p>How can I achieve this?</p>