title: Django comparing lists and filtering objects
body: <p>We want to display all of the pics on our site to a user. In another page we show the user the pics he/she has liked.</p>
  
  <p>After reviewing the functionality it does not make sense for a user to see photos they have already liked in displayallpics.html.</p>
  
  <p>We would like to filter out any pictures that a user has liked and only display photos a user has not liked in displayallpics.html:</p>
  
  <p>Here's the sql for what we want to do: </p>
  
  <pre><code>select * from alphart_picdetails where id not in (select picture_id from alphart_like where user_id = 4);
  </code></pre>
  
  <p>user_id = the user which is logged in -- we just can't get django to do it.</p>
  
  <p>Thanks for your help.</p>
  
  <pre><code>models.py
  
  
  class PicDetails(models.Model): 
      poster = models.ForeignKey(User)
      Title = models.CharField(max_length=50)
      date = models.DateField(("Date"), auto_now_add=True)
  
      def __unicode__(self):
          return self.Title
  
  class Like(models.Model):
     user = models.ForeignKey(User)
     picture = models.ForeignKey(PicDetails)
     created = models.DateTimeField(auto_now_add=True)
     votes = models.IntegerField()
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>def findpics(request): #designed to return all pics posted on the site -the pics user has liked
    like_list = Like.objects.filter(user=request.user)
    user = request.user
    user_list = PicDetails.objects.filter(like=69)
  
    return render_to_response("displayallpics.html", {'user_list':user_list,   'like_list':like_list, 'user':user})
  </code></pre>
  
  <p>template displayallpics.html:</p>
  
  <pre><code>    {% for object in user_list %}
      {{ object.Title }} 
      {% endfor %}    
  </code></pre>