title: retrieve distinct values of manytomanyfield of another manytomanyfield
body: <p>I have a simple question but multiple google searches left me without a nice solution. Currently I am doing the following:</p>
  <pre class="lang-py prettyprint-override"><code>allowed_categories = self.allowed_view.all().difference(self.not_allowed_view.all())
  users = []
  for cat in allowed_categories:
      for member in cat.members.all():
          users.append(member)
  return users
  </code></pre>
  <p>I have a <code>ManyToManyField</code> to <code>Objects</code> that also have a <code>ManyToManyField</code> for instances of <code>User</code>s. In the code above, I am trying to get all the users from all those categories and get a list of all <code>User</code>s.
  Later I would like the same in a method <code>allowed_to_view(self, user_instance)</code> but that's for later.</p>
  <p>How would I achieve this using Django ORM without using nested for-loops?</p>
  <p>[edit]
  My models are as follows:</p>
  <pre class="lang-py prettyprint-override"><code>class RestrictedView(models.Model):
      allowed_view = models.ManyToManyField(Category)
      not_allowed_view = models.ManyToManyField(Category)
  
  class Category(models.Model):
      name = models.CharField(max_length=30)
      members = models.ManyToManyField(User)
  </code></pre>