Skip to content

Commit

Permalink
Merge c26b770 into 3f40aa6
Browse files Browse the repository at this point in the history
  • Loading branch information
maruqu committed Nov 14, 2018
2 parents 3f40aa6 + c26b770 commit 9a48c34
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
8 changes: 1 addition & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
0.9.2 (unreleased)
------------------

- Nothing changed yet.


0.9.2 (unreleased)
------------------

- Nothing changed yet.
- Fix in operator bug.


0.9.1 (2018-08-23)
Expand Down
11 changes: 9 additions & 2 deletions flask_jsonapi/utils/sqlalchemy_django_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class DjangoQueryMixin(object):
'lte': operators.le,
'contains': operators.contains_op,
'notcontains': operators.notcontains_op,
'in': operators.in_op,
'notin': operators.notin_op,
'exact': operators.eq,
'iexact': operators.ilike_op,
'startswith': operators.startswith_op,
Expand All @@ -61,6 +59,11 @@ class DjangoQueryMixin(object):
'day': lambda c, x: extract('day', c) == x
}

_underscore_list_operators = {
'in': operators.in_op,
'notin': operators.notin_op,
}

def filter_by(self, **kwargs):
return self._filter_or_exclude(False, kwargs)

Expand Down Expand Up @@ -130,6 +133,10 @@ def _filter_or_exclude(self, negate, kwargs):
op = self._underscore_operators[token]
q = q.filter(negate_if(op(column, *to_list(value))))
column = None
elif token in self._underscore_list_operators:
op = self._underscore_list_operators[token]
q = q.filter(negate_if(op(column, to_list(value))))
column = None
else:
raise ValueError('No idea what to do with %r' % token)
if column is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,10 @@ def test_greater_than_equal(self, user_repository):
users = user_repository.get_list({'experience_level__gte': 9000})
assert len(users) == 1
assert users[0].name == 'Darth Vader'

def test_in(self, user_repository):
user_repository.create({'name': 'Mr. Bean', 'experience_level': 3})
user_repository.create({'name': 'Darth Vader', 'experience_level': 9000})
user_repository.create({'name': 'Marcin Kopec', 'experience_level': 420})
users = user_repository.get_list({'name__in': ['Mr. Bean', 'Marcin Kopec']})
assert len(users) == 2

0 comments on commit 9a48c34

Please sign in to comment.