title: How do I filter media by include and excluded tags using the Django ORM
body: <p>I have the following models...</p>
  <pre><code>class Media(models.Model):
      name = models.CharField(max_length=255)
      tags = models.ManyToManyField('Tag', blank=True)
  
  class Tag(models.Model):
      name = models.CharField(max_length=255)
  
  class Filter(models.Model):
      name = models.CharField(max_length=255)
      tags_included = models.ManyToManyField('Tag', blank=True, related_name='included_tags')
      tags_excluded = models.ManyToManyField('Tag', blank=True, related_name='excluded_tags')
  
      def get_media(self):
          return &quot;&quot;&quot; return all media that has any tags_included set and remove all media that has tags_excluded set &quot;&quot;&quot;
  </code></pre>
  <p>And I am looking for a method of getting a media selection based on a filter of tags that must be included and tags that must not be included. So I guess it must use __in, filter and exclude some how but cant seem to get anything to run.</p>
  <p>Any help with this would be appreciated, Thanks.</p>