【发布时间】:2021-01-09 09:10:30
【问题描述】:
我发现from rest_framework.filters import SearchFilter 这行给我一个错误
from django.db.models.sql.constants import ORDER_PATTERN
ImportError: cannot import name 'ORDER_PATTERN' from 'django.db.models.sql.constants' (E:\anaconda\envs\AHG_web\lib\site-packages\django\db\models\sql\constants.py)
我使用如下:
class op_ViewSet(viewsets.ModelViewSet) :
# permission_classes = (permissions.IsAuthenticated,)
queryset = Op.objects.all().filter()
serializer_class = op_Serializer
# authentication_classes = [TokenAuthentication , SessionAuthentication , BasicAuthentication]
# pagination_class = PageNumberPagination
# pagination_class = StandardResultsSetPagination
filter_backends = [DjangoFilterBackend , SearchFilter]
filter_class = op_filter
ordering_fields = ['close_date' , ]
ordering = ['close_date']
search_fields = ['website' , 'title' , 'description' , 'organization__name']
@action(detail=True , methods=['Get'])
def attachments(self , request , pk) :
op = self.get_object()
links = Attachments.objects.filter(op_id=op.id)
serializer = attachments_Serializer(links , many=True)
return Response(serializer.data)
以前它工作正常,任何人都可以帮助我解决问题。
【问题讨论】:
-
你安装了哪些版本的 Django 和其他框架?
-
@lain Shelvington (3, 1, 5, 'final', 0)
-
还有rest_framework的版本?
-
django_filters 和 django > 3 存在问题,现已修复。你最近升级了 django,但没有升级 django_filters?
-
从快速搜索看来,这可能是 DRF 过时的问题:github.com/encode/django-rest-framework/pull/7259
标签: django django-rest-framework django-rest-framework-filters