title: Django filter queryset in template
body: <p>I'm still studying in school and still new in Python language &amp; Django framework and I'm trying doing projects to learn the best practice for it.</p>
  
  <p>Right now I'm building a project like following : </p>
  
  <ul>
  <li>Topics Model => which is user can write a new topic </li>
  <li>Replies Model => which is user can write a new reply for a specific topic </li>
  <li>Likes Model => which is user can vote up or down for a topic or reply </li>
  </ul>
  
  <p>it's a little bit close from stackoverflow site .</p>
  
  <p>Models.py</p>
  
  <pre><code>class Topic(models.Model):
  user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
  title = models.CharField(max_length=400)
  like = models.IntegerField(default=0)
  dislike = models.IntegerField(default=0)
  image = models.FileField(blank=True, null=True)
  created_date = models.DateTimeField(auto_now=True)
  
  def __str__(self):
      return self.title[0:51]
  
  
  
  class Reply(models.Model):
  user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
  topic = models.ForeignKey(Topic, on_delete=models.CASCADE)
  reply = models.TextField()
  created_date = models.DateTimeField(auto_now=True)
  
  def likes(self):
      return Likes.objects.filter(reply=self, reply_flag=1).count()
      likes.short_description = 'likes'
  
  def dislikes(self):
      return Likes.objects.filter(reply=self, reply_flag=-1).count()
      dislikes.short_description = 'dislikes'
  
  def __str__(self):
      return self.reply
  
  
  
  class Likes(models.Model):
  user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
  reply = models.ForeignKey(Reply, on_delete=models.CASCADE)
  reply_flag = models.CharField(max_length=5, choices=(
  ('0', 'No'), ('1', 'Positive'), ('-1', 'Negative')))  # 1 = vote up , -1 vote down
  </code></pre>
  
  <p>Views.py</p>
  
  <pre><code># get all topics 
  def Topics(request):
  topics = models.Topic.objects.all()
  return render(request, 'Topics.html', {'topics': topics})
  
  
  
  # get detail of specific topic
  def TopicDetails(request, topic_id):
  topic = get_object_or_404(models.Topic, pk=topic_id)
  return render(request, 'Topic_Details.html', {'topic': topic, 'Likse': models.Likes.objects.all})
  </code></pre>
  
  <p>Templates:</p>
  
  <p>topics.html :</p>
  
  <pre><code> {% for topic in topics %}
  
     {% if topic.image}
        &lt;img src="{{topic.image.url}}"
     {% endif %}
     title : {{ topic.title }}
     by : {{ topic.user }}
     total agree : {{ topic.like }}
     total not agree : {{ topic.dislike }}
  
  {% endfor %}
  </code></pre>
  
  <p>topic.html :</p>
  
  <pre><code> topic title : {{ topic.title }}
  
   {% for reply in topic.reply_set.all %}
  
     reply : {{ topic.reply }}
     by : {{ reply.user }}
     total agree : {% for like in reply.lieks_set.all %} {% if like.reply == reply and like.reply_flag == '1' %} &lt;!-- should be total of vote up --&gt; {% endif %} {%endfor %}
     total not agree : {% for like in reply.lieks_set.all %} {% if like.reply == reply and like.reply_flag == '-1' %} &lt;!-- should be total of vote down --&gt; {% endif %} {%endfor %}
  
  {% endfor %}
  </code></pre>
  
  <p>I faced an issue with filter likes based on reply, user and reply flag (vote up, vote down) in topic.html, 
   I have two questions :</p>
  
  <ul>
  <li>As my knowledge and as I read after search I couldn't filter data in template, So how could I show the filtered data in template based on reply, user and reply flag (vote up, vote down) ?</li>
  <li>Is structure of app is correct ?</li>
  </ul>