title: Creating custom Field Lookups in Django
body: <p>How do you create custom <a href="http://docs.djangoproject.com/en/dev/topics/db/queries/#field-lookups" rel="nofollow noreferrer">field lookups</a> in Django? </p>
  
  <p>When filtering querysets, django provides a set of lookups that you can use: <code>__contains</code>, <code>__iexact</code>, <code>__in</code>, and so forth.  I want to be able to provide a new lookup for my manager, so for instance, someone could say:</p>
  
  <pre><code>twentysomethings = Person.objects.filter(age__within5=25)
  </code></pre>
  
  <p>and get back all the <code>Person</code> objects with an age between 20 and 30.  Do I need to subclass the <code>QuerySet</code> or <code>Manager</code> class to do this?  How would it be implemented?</p>