filters the sequence based on a set of criteria. Parameter names
should be equivalent to the properties accessible in the items of the
sequence. For example, where the items are instances of the Stats
class:
players.filter(home=True, passing_tds=1, rushing_yds=lambda x: x>0)
Returns a sequence with only players on the home team that have a
single passing touchdown and more than zero rushing yards.
If a field specified does not exist for a particular item, that item
is excluded from the result set.
If a field is set to a value, then only items with fields that equal
that value are returned.
If a field is set to a function---which must be a predicate---then
only items with field values satisfying that function will be
returned.
Also, special suffixes that begin with '__' may be added to the end of
a field name to invoke built in predicates. For example, this:
players.filter(receiving_rec=lambda v: v > 0)
Is equivalent to:
players.filter(receiving_rec__gt=0)
Other suffixes includes gt, le, lt, ne, ge, etc.
(Django users should feel right at home.)
|