Skip to content

Commit 4a4862f

Browse files
stephenfindaxtens
authored andcommitted
Add support for django-filter 1.1
There's one warning to handle here. Signed-off-by: Stephen Finucane <stephen@that.guru> Signed-off-by: Daniel Axtens <dja@axtens.net> (backported from commit 4ad2558 to not include changes to requirements-*.txt, just release note, code and tox.ini changes.) Signed-off-by: Daniel Axtens <dja@axtens.net>
1 parent b995312 commit 4a4862f

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Requirements
4747

4848
- Django REST Framework (3.4 - 3.8)
4949

50-
- Django Filters (1.0)
50+
- Django Filters (1.0 - 1.1)
5151

5252
Development Installation
5353
------------------------

patchwork/api/filters.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from django.forms import ModelMultipleChoiceField as BaseMultipleChoiceField
2727
from django.forms.widgets import MultipleHiddenInput
2828

29+
from patchwork.compat import NAME_FIELD
2930
from patchwork.models import Bundle
3031
from patchwork.models import Check
3132
from patchwork.models import CoverLetter
@@ -151,8 +152,8 @@ class UserFilter(ModelMultipleChoiceFilter):
151152
class TimestampMixin(FilterSet):
152153

153154
# TODO(stephenfin): These should filter on a 'updated_at' field instead
154-
before = IsoDateTimeFilter(name='date', lookup_expr='lt')
155-
since = IsoDateTimeFilter(name='date', lookup_expr='gte')
155+
before = IsoDateTimeFilter(lookup_expr='lt', **{NAME_FIELD: 'date'})
156+
since = IsoDateTimeFilter(lookup_expr='gte', **{NAME_FIELD: 'date'})
156157

157158

158159
class SeriesFilterSet(TimestampMixin, FilterSet):

patchwork/compat.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@
4141
from rest_framework.filters import DjangoFilterBackend # noqa
4242

4343

44+
# NAME_FIELD
45+
#
46+
# The django-filter library renamed 'Filter.name' to 'Filter.field_name' in
47+
# 1.1.
48+
#
49+
# https://django-filter.readthedocs.io/en/master/guide/migration.html#migrating-to-2-0
50+
51+
if settings.ENABLE_REST_API:
52+
import django_filters # noqa
53+
54+
if django_filters.VERSION >= (1, 1):
55+
NAME_FIELD = 'field_name'
56+
else:
57+
NAME_FIELD = 'name'
58+
59+
4460
# reverse, reverse_lazy
4561
#
4662
# The reverse and reverse_lazy functions have been moved to django.urls in
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
upgrade:
3+
- |
4+
`django-filter 1.1
5+
<https://github.com/carltongibson/django-filter/releases/tag/1.1.0>`_ is
6+
now supported.

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ deps =
1313
django{18,19}: djangorestframework>=3.4,<3.7
1414
django110: djangorestframework>=3.4,<3.9
1515
django111: djangorestframework>=3.6,<3.9
16-
django{18,19,110,111}: django-filter>=1.0,<1.1
16+
django18: django-filter>=1.0,<1.1
17+
django{19,110,111}: django-filter>=1.0,<1.2
1718
setenv =
1819
DJANGO_SETTINGS_MODULE = patchwork.settings.dev
1920
PYTHONDONTWRITEBYTECODE = 1

0 commit comments

Comments
 (0)