site-packages/django_filters/filters.py:33
过滤器类
"AllValuesFilter",
"AllValuesMultipleFilter",
"BaseCSVFilter",
"BaseInFilter",
"BaseRangeFilter",
"BooleanFilter",
"CharFilter",
"ChoiceFilter",
"DateFilter",
"DateFromToRangeFilter",
"DateRangeFilter",
"DateTimeFilter",
"DateTimeFromToRangeFilter",
"DurationFilter",
"Filter",
"IsoDateTimeFilter",
"IsoDateTimeFromToRangeFilter",
"LookupChoiceFilter",
"ModelChoiceFilter",
"ModelMultipleChoiceFilter",
"MultipleChoiceFilter",
"NumberFilter",
"NumericRangeFilter",
"OrderingFilter",
"RangeFilter",
"TimeFilter",
"TimeRangeFilter",
"TypedChoiceFilter",
"TypedMultipleChoiceFilter",
"UUIDFilter",
过滤器类参数清单
field_name参数,可选,默认使用过滤器的名字作为要查询的字段名
lookup_expr参数,可选,默认使用exact作为lookup表达式
class Filter:
def __init__(
self,
field_name=None,
lookup_expr=None,
*,
label=None,
method=None,
distinct=False,
exclude=False,
**kwargs
):
if lookup_expr is None:
lookup_expr = settings.DEFAULT_LOOKUP_EXPR # 默认是exact,完全匹配
self.field_name = field_name
self.lookup_expr = lookup_expr
self.label = label
self.method = method
self.distinct = distinct
self.exclude = exclude
self.extra = kwargs
self.extra.setdefault("required", False)
self.creation_counter = Filter.creation_counter
Filter.creation_counter += 1
Lookups 清单(lookup_expr可以设置的值)
date
year
month
day
week_day
hour
minute
second
exact
iexact
contains
icontains
in
gt
gte
lt
lte
startswith
istartswith
endswith
iendswith
range
isnull
regex
iregex
search
contained_by
overlap
has_key
has_keys
has_any_keys
trigram_similar
Meta类字段备忘录
https://django-filter.readthedocs.io/en/stable/ref/filterset.html#meta-options
model
fields
exclude
form
filter_overrides