5
5
import copy
6
6
from collections import defaultdict
7
7
8
+ from django import get_version as get_django_version
8
9
from django .contrib .contenttypes .models import ContentType
9
10
from django .core .exceptions import FieldDoesNotExist
10
11
from django .db .models .query import ModelIterable , Q , QuerySet
@@ -157,18 +158,34 @@ def not_instance_of(self, *args):
157
158
# Implementation in _translate_polymorphic_filter_defnition."""
158
159
return self .filter (not_instance_of = args )
159
160
160
- def _filter_or_exclude (self , negate , * args , ** kwargs ):
161
- # We override this internal Django functon as it is used for all filter member functions.
162
- q_objects = translate_polymorphic_filter_definitions_in_args (
163
- self .model , args , using = self .db
164
- )
165
- # filter_field='data'
166
- additional_args = translate_polymorphic_filter_definitions_in_kwargs (
167
- self .model , kwargs , using = self .db
168
- )
169
- return super (PolymorphicQuerySet , self )._filter_or_exclude (
170
- negate , * (list (q_objects ) + additional_args ), ** kwargs
171
- )
161
+ # Makes _filter_or_exclude compatible with the change in signature introduced in django at 9c9a3fe
162
+ if get_django_version () >= "3.2" :
163
+ def _filter_or_exclude (self , negate , args , kwargs ):
164
+ # We override this internal Django function as it is used for all filter member functions.
165
+ q_objects = translate_polymorphic_filter_definitions_in_args (
166
+ queryset_model = self .model , args = args , using = self .db
167
+ )
168
+ # filter_field='data'
169
+ additional_args = translate_polymorphic_filter_definitions_in_kwargs (
170
+ queryset_model = self .model , kwargs = kwargs , using = self .db
171
+ )
172
+ args = list (q_objects ) + additional_args
173
+ return super (PolymorphicQuerySet , self )._filter_or_exclude (
174
+ negate = negate , args = args , kwargs = kwargs
175
+ )
176
+ else :
177
+ def _filter_or_exclude (self , negate , * args , ** kwargs ):
178
+ # We override this internal Django function as it is used for all filter member functions.
179
+ q_objects = translate_polymorphic_filter_definitions_in_args (
180
+ self .model , args , using = self .db
181
+ )
182
+ # filter_field='data'
183
+ additional_args = translate_polymorphic_filter_definitions_in_kwargs (
184
+ self .model , kwargs , using = self .db
185
+ )
186
+ return super (PolymorphicQuerySet , self )._filter_or_exclude (
187
+ negate , * (list (q_objects ) + additional_args ), ** kwargs
188
+ )
172
189
173
190
def order_by (self , * field_names ):
174
191
"""translate the field paths in the args, then call vanilla order_by."""
@@ -521,4 +538,4 @@ def get_real_instances(self, base_result_objects=None):
521
538
if not self .model .polymorphic_query_multiline_output :
522
539
return olist
523
540
clist = PolymorphicQuerySet ._p_list_class (olist )
524
- return clist
541
+ return clist
0 commit comments