title: Check whether object is in QuerySet of related objects
body: <p>I am building an application having to do with game achievements, and I want to display for each game, a page that lists the related achievements. That is done. </p>
  
  <p>However, I also want each user to be able to see in that list which achievements they have completed. </p>
  
  <p>My model is like this:</p>
  
  <pre><code>class Achievement(models.Model):
      game = models.ForeignKey(Game)
      ...
  
  class Game(models.Model):
      ...
  
  class GameProfile(models.Model):
      achievements = models.ManyToManyField(Achievement, through='Achieved')
      ...
  
  class Achieved(models.Model):
      profile = models.ForeignKey(GameProfile)
      achievement = models.ForeignKey(Achievement)
      curr_count = models.PositiveSmallIntegerField()
  </code></pre>
  
  <p>In the game template page, I get all the achievements for the current game through the relationship with the Achievement model (ie <code>achievements = game.achievement_set.all</code>). Then I do a <code>{% for ach in achievements %}</code> on them and output a <code>&lt;li&gt;</code> for each. 
  If a user is logged in, I also want to display the curr_count associated with the achievement. So I need a list of Achieved objects for the specific GameProfile (think of it as the current user). </p>
  
  <p>The problem is that I cannot do <code>{% if ach in achieved %}</code> (where ach is an Achievement instance and achieved an Achieved QuerySet), obviously. </p>
  
  <p>I also thought I could get a QuerySet with the Achievements the user has achieved, but that lacks the <code>curr_count</code>, which I want to display. </p>
  
  <p>I think what I want is some kind of list or dictionary with the Achievements of the user against which I can test if a specific Achievement is a member, but which will also carry the curr_count variable. Another solution might be to somehow add <code>curr_count</code> as a field to a QuerySet of Achievement objects (which will be the ones the user has achieved). </p>
  
  <p>Can you suggest how to accomplish this in django? </p>