title: Querying for followers in news-feed-based data model in Django
body: <p>I have this following (simplified) model in Django which is very similar to the Pinterest data model:</p>
  
  <pre><code>class UserProfile(models.Model):
      user = models.OneToOneField(User)
  
  class Collection(models.Model):
      owner = models.ForeignKey(User,related_name='collection_owner')
      followers = models.ManyToManyField(User, related_name='collection_followers', null=True, blank=True, default = None)
  
  class Item(models.Model):
      collections = models.ManyToManyField(Collection,blank=True,null=True)
  </code></pre>
  
  <p>I have a User model, a UserProfile model that maps 1-1 with a user, a Collection model which has an owner and followers and items that can be part of multiple collections. I'm struggling with determining how to execute the following queries in Django:</p>
  
  <p>Get all the followers of a given user. The definition of a follower is one that follows at least one collection that is owned by that particular user.</p>
  
  <p>Get all the distinct items of the collection a user follows.</p>
  
  <p>I'm not sure if I can do these in a single query or do I have to break it up in several queries? What would be the best approach and are there any trade offs?</p>
  
  <p>Thanks for any help.</p>