Skip to content

Commit dd90504

Browse files
authored
add ne operator (#260)
1 parent 5cbb254 commit dd90504

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

docs/source/crud/piccolo_crud.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ time fields the following operators are allowed:
135135
* ``gt``: Greater Than
136136
* ``gte``: Greater Than or Equal
137137
* ``e``: Equal (default)
138+
* ``ne``: Not Equal
138139

139140
To specify which operator to use, pass a query parameter like ``field__operator=operator_name``.
140141
For example ``duration__operator=gte``.

piccolo_api/crud/endpoints.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
IsNull,
1919
LessEqualThan,
2020
LessThan,
21+
NotEqual,
2122
)
2223
from piccolo.columns.operators.comparison import ComparisonOperator
2324
from piccolo.query.methods.delete import Delete
@@ -53,6 +54,7 @@
5354
"gt": GreaterThan,
5455
"gte": GreaterEqualThan,
5556
"e": Equal,
57+
"ne": NotEqual,
5658
"is_null": IsNull,
5759
"not_null": IsNotNull,
5860
}

piccolo_api/fastapi/endpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def modify_signature(
492492
description=(
493493
f"Which operator to use for `{field_name}`. "
494494
"The options are `e` (equals - default) `lt`, "
495-
"`lte`, `gt`, `gte`, `is_null`, and "
495+
"`lte`, `gt`, `gte`, `ne`, `is_null`, and "
496496
"`not_null`."
497497
),
498498
),

tests/crud/test_crud_endpoints.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,21 @@ def test_operator_gt(self):
964964
{"rows": [{"id": 1, "name": "Star Wars", "rating": 93}]},
965965
)
966966

967+
def test_operator_ne(self):
968+
"""
969+
Test operator - not equals.
970+
"""
971+
client = TestClient(PiccoloCRUD(table=Movie, read_only=False))
972+
response = client.get(
973+
"/",
974+
params={"__order": "id", "rating": "90", "rating__operator": "ne"},
975+
)
976+
self.assertEqual(response.status_code, 200)
977+
self.assertEqual(
978+
response.json(),
979+
{"rows": [{"id": 1, "name": "Star Wars", "rating": 93}]},
980+
)
981+
967982
def test_operator_null(self):
968983
"""
969984
Test operators - `is_null` / `not_null`.

0 commit comments

Comments
 (0)