title: How do I pass a boolean for each post in my function view?
body: <h3>My <code>views.py</code></h3>
  
  <pre><code>def problems_list(request):
      queryset = Post.objects.filter(created__range=['2020-03-01', '2020-03-31'])
  
      def is_liked(self):
          #if currently logged on user has already liked the post then
              is_liked = True
          #else
              is_liked = False
  
  
      context = {
          'posts': queryset,
          'is_liked': is_liked
      }
      return render(request, 'main/problem.html', context)
  </code></pre>
  
  <h3>My <code>model.py</code></h3>
  
  <pre><code>class Post(models.Model):
      likes = models.ManyToManyField(User, related_name='likes', blank=True, default=None)
  </code></pre>
  
  <p>On each post I want to check wether the user has liked the post and if he has then pass a boolean variable tied to that post so that it shows he liked it. Im not sure how to add a variable that is tied to each post. I was reading some and saw that I might need a second model for my likes. Is this a better option?</p>
  
  <p>I can run this in the shell for a single post but I want to be able to call it on all post.</p>
  
  <pre><code>In [1]: from main.models import Post
  
  In [2]: from django.contrib.auth.models import User
  
  In [3]: user = User.objects.first()
  
  In [4]: post = Post.objects.first()
  
  In [5]: post.likes.all()
  Out[5]: &lt;QuerySet [&lt;User: user1&gt;, &lt;User: user2&gt;, &lt;User: user3&gt;]&gt;
  
  In [6]: post.likes.filter(username = user).exists()
  Out[6]: True
  </code></pre>