Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not import QUERY_TERMS

Tags:

python

django

I am running a website through Python and Django.

Django-filters=2.1 installed
Django=2.1 installed

When I run, I'm getting the below error.

importError: Could not import 'django_filters.rest_framework.DjangoFilterBackend' for API setting 'DEFAULT_FILTER_BACKENDS'. 
ImportError: cannot import name 'QUERY_TERMS' from 
'django.db.models.sql.constants' (C:\Users\Android V\AppData\Loc
    al\Programs\Python\Python37-32\lib\site-packages\django\db\models\sql\constants.
    py).
like image 732
Karthik J Avatar asked Dec 03 '19 13:12

Karthik J


1 Answers

Short answer: upgrade your django-filter package (not to be confused with the django package) to the latest version.

The reason this fails is because in Django there has been a changeset [GitHub] that indeed removed the QUERY_TERMS constant from the django.db.models.sql.constants, to allow the ModelAdmin to use any lookup. This changes has been deployed in django-2.1 (so in django-2.0, there was still a QUERY_TERMS constant).

The django-filter-1.1.0 package still used that constant. This is fixed in a changeset [GitHub], and as of django-filter-2.0.0, this is no longer used.

like image 62
Willem Van Onsem Avatar answered Nov 15 '22 02:11

Willem Van Onsem