title: Django: distinct QuerySet based on a related field
body: <p>In my Django app I allow users to create collections of movies by category. This is represented using 3 models, Movie, Collection, and Addition (the Addition model stores movie, collection, and user instances). Simplified versions of all three models are below.</p>
  
  <pre><code>class Movie(models.Model):
      name = models.CharField(max_length=64)
  
  class Collection(models.Model):
      name = models.CharField(max_length=64)
      user = models.ForeignKey(User)
  
  class Addition(models.Model):
      user = models.ForeignKey(User)
      movie = models.ForeignKey(Movie)
      collection = models.ForeignKey(Collection)
  </code></pre>
  
  <p>So for example a user could create a collection called "80's movies", and add the movie "Indiana Jones" to their collection.</p>
  
  <p>My question is: how do I display a distinct list of movies based on a set of query filters? Right now I am getting a bunch of duplicates for those movies that have been added to more than one collection.  I would normally use distinct() to get distinct objects, but in this case I need distinct movies rather than distinct additions, but I need to query the Addition model because I want to allow the user to view movies added by their friends.</p>
  
  <p>Am I setting up my models in an optimal way? Any advice/help would be much appreciated.</p>
  
  <p>Thanks!</p>