Skip to content

Commit 36f9ac0

Browse files
committed
Add Django 4.0 compatibility
1 parent 581e2d1 commit 36f9ac0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

django_select2/forms.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
from itertools import chain
5353
from pickle import PicklingError # nosec
5454

55+
import django
5556
from django import forms
56-
from django.contrib.admin.utils import lookup_needs_distinct
5757
from django.contrib.admin.widgets import SELECT2_TRANSLATIONS
5858
from django.core import signing
5959
from django.db.models import Q
@@ -64,6 +64,11 @@
6464
from .cache import cache
6565
from .conf import settings
6666

67+
if django.VERSION < (4, 0):
68+
from django.contrib.admin.utils import lookup_needs_distinct as lookup_spawns_duplicates
69+
else:
70+
from django.contrib.admin.utils import lookup_spawns_duplicates
71+
6772

6873
class Select2Mixin:
6974
"""
@@ -407,15 +412,15 @@ def filter_queryset(self, request, term, queryset=None, **dependent_fields):
407412
or_queries = [Q(**{orm_lookup: term}) for orm_lookup in search_fields]
408413
select |= reduce(operator.or_, or_queries)
409414
use_distinct |= any(
410-
lookup_needs_distinct(queryset.model._meta, search_spec)
415+
lookup_spawns_duplicates(queryset.model._meta, search_spec)
411416
for search_spec in search_fields
412417
)
413418

414419
if dependent_fields:
415420
select &= Q(**dependent_fields)
416421

417422
use_distinct |= any(
418-
lookup_needs_distinct(queryset.model._meta, search_spec)
423+
lookup_spawns_duplicates(queryset.model._meta, search_spec)
419424
for search_spec in dependent_fields.keys()
420425
)
421426

0 commit comments

Comments
 (0)