Skip to content

Commit

Permalink
?column_notcontains= table filter, closes #2287
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Feb 28, 2024
1 parent c863443 commit f99c2f5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions datasette/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ class Filters:
'{c} contains "{v}"',
format="%{}%",
),
TemplatedFilter(
"notcontains",
"does not contain",
'"{c}" not like :{p}',
'{c} does not contain "{v}"',
format="%{}%",
),
TemplatedFilter(
"endswith",
"ends with",
Expand Down
3 changes: 3 additions & 0 deletions docs/json_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ You can filter the data returned by the table based on column values using a que
``?column__contains=value``
Rows where the string column contains the specified value (``column like "%value%"`` in SQL).

``?column__notcontains=value``
Rows where the string column does not contain the specified value (``column not like "%value%"`` in SQL).

``?column__endswith=value``
Rows where the string column ends with the specified value (``column like "%value"`` in SQL).

Expand Down
5 changes: 5 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"args,expected_where,expected_params",
[
((("name_english__contains", "foo"),), ['"name_english" like :p0'], ["%foo%"]),
(
(("name_english__notcontains", "foo"),),
['"name_english" not like :p0'],
["%foo%"],
),
(
(("foo", "bar"), ("bar__contains", "baz")),
['"bar" like :p0', '"foo" = :p1'],
Expand Down

0 comments on commit f99c2f5

Please sign in to comment.