|
5 | 5 | from django.db.models import Q, Prefetch, Manager
|
6 | 6 | import six
|
7 | 7 | from functools import reduce
|
| 8 | +from rest_framework import __version__ as drf_version |
8 | 9 | from rest_framework import serializers
|
9 | 10 | 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 |
11 | 16 | from rest_framework.filters import BaseFilterBackend, OrderingFilter
|
12 | 17 |
|
13 | 18 | from dynamic_rest.utils import is_truthy
|
|
26 | 31 |
|
27 | 32 | patch_prefetch_one_level()
|
28 | 33 |
|
| 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 | + |
29 | 41 |
|
30 | 42 | def OR(a, b):
|
31 | 43 | return a | b
|
@@ -148,7 +160,7 @@ def rewrite_filters(fs, serializer):
|
148 | 160 | out = {}
|
149 | 161 | for node in fs.values():
|
150 | 162 | filter_key, field = node.generate_query_key(serializer)
|
151 |
| - if isinstance(field, (BooleanField, NullBooleanField)): |
| 163 | + if isinstance(field, DRF_BOOLEAN_FIELD): |
152 | 164 | node.value = is_truthy(node.value)
|
153 | 165 | out[filter_key] = node.value
|
154 | 166 |
|
|
0 commit comments