title: Check if element is in a model - Django templates
body: <p>i'm trying to make a like button. And everything works fine except for the fact that i can't check (inside the template) if something is already liked by the user. In other words, i can't check for an existing row in the database.</p>
  <p>Im trying this for the template:
  If the user likes the post. That post shows a filled heart, otherwise it shows only a heart contour</p>
  <pre><code>{% for post in posts %}
     {% if post in likelist %}
        &lt;i class=&quot;fa fa-heart like&quot; data-id=&quot;{{ post.id }}&quot; id=&quot;like-{{ post.id }}&quot; style=&quot;color:red;&quot;&gt;&lt;/i&gt;
     {% else %}
        &lt;i class=&quot;fa fa-heart-o like&quot; data-id=&quot;{{ post.id }}&quot; id=&quot;like-{{ post.id }}&quot; style=&quot;color:red;&quot;&gt; 
     &lt;/i&gt;
     {% endif %} 
  {% endfor %}
  </code></pre>
  <p>But the if statement is giving always False, even when the user actually likes the post.</p>
  <p>Here is the model:</p>
  <pre><code>class Likelist(models.Model):
      user = models.ForeignKey('User', on_delete=models.CASCADE, related_name='liker')
      likes = models.ForeignKey('Posts', on_delete=models.CASCADE, related_name='likes')
  
      def __str__(self):
          return f&quot;{self.user} likes {self.likes}&quot;
  </code></pre>
  <p>And i'm passing the context in views.py through render</p>
  <pre><code>return render(request, &quot;network/profile.html&quot;, {
        #[...]some other contexts
        &quot;posts&quot;: Posts.objects.filter(user=user_id).order_by('-timestamp'), 
        &quot;likelist&quot;: Likelist.objects.filter(user=request.user),
      })
  </code></pre>
  <p>If i try to print it in a HTML tag ( {{likelist}} or {{posts}} ) the querysets appears so the context is passing fine.
  I don't know why the conditional isn't checking the existence of the element in the database</p>