Angelo
Angelo
This guy hasn't written anything yet

注册于 1 year ago

回答
2
文章
1
关注者
1

你注册的两个路由冲突了
请求api/crud_demo/ceshi/的时候实际是去跟CrudDemoModelViewSet的retrieve接口(api/crud_demo/{id}/)匹配, 找不到id="ceshi"的对象所以就报错了

简单实现了一版已提交dev分支, 可以拉取最新代码看一下

    filter_fields = ["^name", "~username", "^mobile", "is_active", "dept", "user_type", "$dept__name"]
    
    filter_fields = {
        "name": ["icontains"],
        "mobile": ["iregex"],
        "username": ["icontains"],
        "is_active": ["icontains"],
        "dept": ["exact"],
        "user_type": ["exact"],
        "dept__name": ["icontains"],
    }

两种配置均可, 列表模式也同时支持配置lookup_prefixes, 类似SearchFilter, 可选参数如下

    lookup_prefixes = {
        "^": "istartswith",
        "=": "iexact",
        "@": "search",
        "$": "iregex",
        "~": "icontains",
    }

发布
问题