from rest_framework.filters import SearchFilter generates error as cannot import name 'ORDER_PATTERN' from 'django.db

1.9k Views Asked by At

I found out that the line from rest_framework.filters import SearchFilter generates me an error as

 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)

I used that as below:

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)

previously it was working fine, can anyone help me with the solution.

2

There are 2 best solutions below

0
Tom On

This looks like a compatibility problem between the versions of Django and Django Rest Framework. Upgrading to the latest version of DRF should resolve it.

(I had this error after upgrading Django 3.0.x to 3.2)

0
samuelbianch On

Update all packeges you have installed in your project

pip install <package_name> --upgrade