title: Django dynamically create not equal q objects
body: <p>I'm working on creating dynamic filters using nested AND / OR logic, and would like to include NOT as an option. This leverages Q objects to create the nested AND / OR logic.</p>
  <p>The class takes in a json object like so:</p>
  <pre><code>filters = {
      'and': {
          &quot;url__is&quot;: &quot;www.test.com&quot;,
          &quot;name__is&quot;: &quot;test&quot;
      }
  }
  </code></pre>
  <p>This gets compiled down to</p>
  <pre><code>.filter(Q(url__is='www.test.com') and Q(name__is='test')
  </code></pre>
  <p>This works via a recursive function that really just does this on each level of the json tree.</p>
  <pre><code>return source_queryset.filter(reduce(and_, filter_list))
  </code></pre>
  <p>and_ is from the python operator library and has been working great. I'd like to add NOT as an option as well though, and can't seem to find an equivalent option to reduce a list of Q objects to.</p>
  <p>Does anyone know a way to use reduce in a way that creates the idea of not equal to a list of q objects?</p>