Skip to content

Commit 3b90146

Browse files
authored
Merge pull request #354 from apo5tol/django_42_support
Django 4.2 support
2 parents ed69e5a + b65181c commit 3b90146

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

dynamic_rest/filters.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
from django.db.models import Q, Prefetch, Manager
66
import six
77
from functools import reduce
8+
from rest_framework import __version__ as drf_version
89
from rest_framework import serializers
910
from rest_framework.exceptions import ValidationError
10-
from rest_framework.fields import BooleanField, NullBooleanField
11+
try:
12+
from rest_framework.fields import BooleanField, NullBooleanField
13+
except ImportError:
14+
# DRF >= 3.14.0
15+
from rest_framework.fields import BooleanField
1116
from rest_framework.filters import BaseFilterBackend, OrderingFilter
1217

1318
from dynamic_rest.utils import is_truthy
@@ -26,6 +31,13 @@
2631

2732
patch_prefetch_one_level()
2833

34+
DRF_VERSION = drf_version.split('.')
35+
if int(DRF_VERSION[0]) >= 3 and int(DRF_VERSION[1]) >= 14:
36+
# NullBooleanField deprecated in DRF >= 3.14
37+
DRF_BOOLEAN_FIELD = BooleanField
38+
else:
39+
DRF_BOOLEAN_FIELD = (BooleanField, NullBooleanField)
40+
2941

3042
def OR(a, b):
3143
return a | b
@@ -148,7 +160,7 @@ def rewrite_filters(fs, serializer):
148160
out = {}
149161
for node in fs.values():
150162
filter_key, field = node.generate_query_key(serializer)
151-
if isinstance(field, (BooleanField, NullBooleanField)):
163+
if isinstance(field, DRF_BOOLEAN_FIELD):
152164
node.value = is_truthy(node.value)
153165
out[filter_key] = node.value
154166

install_requires.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Django>=2.2,<4.2
1+
Django>=2.2,<4.3
22
djangorestframework>=3.11.2,<3.15
33
inflection>=0.4.0
44
requests

requirements.benchmark.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dj-database-url==0.3.0
22
django-debug-toolbar==1.7
3-
Django>=2.2,<4.2
3+
Django>=2.2,<4.3
44
djangorestframework>=3.11.2,<3.15
55
djay>=0.0.9
66
flake8>=3.0

tox.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ addopts=--tb=short
44
[tox]
55
envlist =
66
py310-lint,
7-
{py37,py38,py39,py310}-django{22,31,32,40,41}-drf{311,312,313,314},
7+
{py37,py38,py39,py310}-django{22,31,32,40,41,42}-drf{311,312,313,314},
88

99
[testenv]
1010
commands = ./runtests.py --fast {posargs} --coverage -rw
@@ -16,6 +16,7 @@ deps =
1616
django32: Django>=3.2,<3.3
1717
django40: Django>=4.0,<4.1
1818
django41: Django>=4.1,<4.2
19+
django42: Django>=4.2,<4.3
1920
drf311: djangorestframework>=3.11.2,<3.12
2021
drf312: djangorestframework>=3.12,<3.13
2122
drf313: djangorestframework>=3.13,<3.14
@@ -29,6 +30,6 @@ deps = -rrequirements.txt
2930
[testenv:py310-drf314-benchmarks]
3031
commands = ./runtests.py --benchmarks
3132
deps =
32-
Django==4.1.1
33+
Django==4.2.1
3334
djangorestframework==3.14
3435
-rrequirements.benchmark.txt

0 commit comments

Comments
 (0)