Use conditional function definition
parent
45215ff6c3
commit
fa6808e9b3
|
|
@ -158,6 +158,22 @@ class PolymorphicQuerySet(QuerySet):
|
||||||
# Implementation in _translate_polymorphic_filter_defnition."""
|
# Implementation in _translate_polymorphic_filter_defnition."""
|
||||||
return self.filter(not_instance_of=args)
|
return self.filter(not_instance_of=args)
|
||||||
|
|
||||||
|
# Makes _filter_or_exclude compatible with the change in signature introduced in django at 9c9a3fe
|
||||||
|
if get_django_version() >= "3.2":
|
||||||
|
def _filter_or_exclude(self, negate, args, kwargs):
|
||||||
|
# We override this internal Django function as it is used for all filter member functions.
|
||||||
|
q_objects = translate_polymorphic_filter_definitions_in_args(
|
||||||
|
queryset_model=self.model, args=args, using=self.db
|
||||||
|
)
|
||||||
|
# filter_field='data'
|
||||||
|
additional_args = translate_polymorphic_filter_definitions_in_kwargs(
|
||||||
|
queryset_model=self.model, kwargs=kwargs, using=self.db
|
||||||
|
)
|
||||||
|
args = list(q_objects) + additional_args
|
||||||
|
return super(PolymorphicQuerySet, self)._filter_or_exclude(
|
||||||
|
negate=negate, args=args, kwargs=kwargs
|
||||||
|
)
|
||||||
|
else:
|
||||||
def _filter_or_exclude(self, negate, *args, **kwargs):
|
def _filter_or_exclude(self, negate, *args, **kwargs):
|
||||||
# We override this internal Django function as it is used for all filter member functions.
|
# We override this internal Django function as it is used for all filter member functions.
|
||||||
q_objects = translate_polymorphic_filter_definitions_in_args(
|
q_objects = translate_polymorphic_filter_definitions_in_args(
|
||||||
|
|
@ -523,21 +539,3 @@ class PolymorphicQuerySet(QuerySet):
|
||||||
return olist
|
return olist
|
||||||
clist = PolymorphicQuerySet._p_list_class(olist)
|
clist = PolymorphicQuerySet._p_list_class(olist)
|
||||||
return clist
|
return clist
|
||||||
|
|
||||||
|
|
||||||
# Makes _filter_or_exclude compatible with the change in signature introduced in django at 9c9a3fe
|
|
||||||
if get_django_version() >= "3.2":
|
|
||||||
def _filter_or_exclude(self, negate, args, kwargs):
|
|
||||||
# We override this internal Django function as it is used for all filter member functions.
|
|
||||||
q_objects = translate_polymorphic_filter_definitions_in_args(
|
|
||||||
queryset_model=self.model, args=args, using=self.db
|
|
||||||
)
|
|
||||||
# filter_field='data'
|
|
||||||
additional_args = translate_polymorphic_filter_definitions_in_kwargs(
|
|
||||||
queryset_model=self.model, kwargs=kwargs, using=self.db
|
|
||||||
)
|
|
||||||
args = list(q_objects) + additional_args
|
|
||||||
return super(PolymorphicQuerySet, self)._filter_or_exclude(
|
|
||||||
negate=negate, args=args, kwargs=kwargs
|
|
||||||
)
|
|
||||||
PolymorphicQuerySet._filter_or_exclude = _filter_or_exclude
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue