You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
from rest_framework import serializers
from django_filters . rest_framework import FilterSet
import django_filters
from app . models import TP
class SerialMyModel ( serializers . ModelSerializer ) :
class Meta :
model = TP
fields = " __all__ "
class SerialFilter ( FilterSet ) :
"""
过滤器,支持模糊查询
record_time, 日期时间格式, 如 2023-01-01 00:00:00
police_id, 支持模糊匹配
event_type, 支持模糊匹配
"""
record_time = django_filters . DateTimeFilter ( field_name = ' record_time ' , lookup_expr = ' icontains ' )
police_id = django_filters . CharFilter ( field_name = ' police_id ' , lookup_expr = ' icontains ' )
event_type = django_filters . CharFilter ( field_name = ' event_type ' , lookup_expr = ' icontains ' )
class Meta :
# 指定模型
models = TP
# 指定需要模糊查询的字段
fields = ( " record_time " , " police_id " , " event_type " , )