How do you create custom field lookups in Django?
When filtering querysets, django provides a set of lookups that you can use: __contains
, __iexact
, __in
, and so forth. I want to be able to provide a new lookup for my manager, so for instance, someone could say:
twentysomethings = Person.objects.filter(age__within5=25)
and get back all the Person
objects with an age between 20 and 30. Do I need to subclass the QuerySet
or Manager
class to do this? How would it be implemented?