title: Django filter: Finding a best practice
body: <p>I am finding a way to achieve a filter in a fewer code like, my current filter working fine below:</p>
  
  <pre><code>if company == 1:
      unknownFood = food.filter(
          purchase__credit = 2
          company__name__isnull=True
      )
  elif company == 2:
      unknownFood = food.filter(
          purchase__credit = 2
          company__name__isnull=False
      )
  else:
      unknownFood = food.filter(
          purchase__credit = 2
      )
  </code></pre>
  
  <p>Above code, appeared with few repeated line of code and I believe this is not a best practice.</p>
  
  <p>I am trying to achieve this with a fewer line code than above code.</p>
  
  <p>here you go:</p>
  
  <pre><code>if company == 1:
      isNull = True
  elif company == 2:
      isNull = False
  else:
      pass
  
  unknownFood = food.filter(
          purchase__credit = 2
          company__name__isnull=isNull
      )
  </code></pre>
  
  <p>if i do like above shortened way, it fires me an error, coz </p>
  
  <p><code>company__name__isnull</code> is equeal to <code>false</code> or <code>true</code> and its third block gets neither true or false</p>
  
  <p>Can anyone suggest me the best way to achieve this?</p>