title: Combining filters for a Django queryset
body: <p>Lets say I have models that look like this:</p>
  
  <pre><code>class Sauce(models.Model):
      ...
  
  class Topping(models.Model):
      ...
  
  class Pizza(models.Model):
      sauces = models.ManyToManyField(Sauce, related_name='pizzas')
      toppings = models.ManyToManyField(Topping, related_name='pizzas')
      geo_type = models.CharField(max_length=50, choices=(('NY', 'New York'), ('IT', 'Italy')))
  </code></pre>
  
  <p>Now, I have an endpoint which accepts URL parameters for filtering the pizza table. For example, one time I might get the following:</p>
  
  <pre><code>{
      "sauces": [1, 4],
      "toppings": [4, 7],
      "geo_type": "NY"
  }
  </code></pre>
  
  <p>Using this, I would simply filter using the following code:</p>
  
  <pre><code>Pizza.objects.filter(sauces__in=url_params["sauces"], toppings__in=url_params["toppings"], geo_type=url_params["geo_type"])
  </code></pre>
  
  <p>And this would work perfectly fine. However, sometimes I might get URL parameters which look like this:</p>
  
  <pre><code>{
      "sauces": [],
      "toppings": [4, 7],
      "geo_type": "NY"
  }
  </code></pre>
  
  <p>Notice the empty array for the sauces parameter. This means that for this request, I don't care about sauces and it can be anything. Now the query would be something like this:</p>
  
  <pre><code>Pizza.objects.filter(toppings__in=url_params["toppings"], geo_type=url_params["geo_type"])
  </code></pre>
  
  <p>Once again, this works as expected. However, the issues is that I have a lot of these fields to filter, and the number of combinations is huge. Is there some to just tell my queryset to ignore a filter if it is an empty array? And if the geo_type is an empty string or null, it should ignore those too. Hopefully I have gotten my point across. </p>
  
  <p>Thanks for any help.</p>