Skip to content

Commit 0ad109a

Browse files
committed
add support for NegatedExpression
1 parent 6e5995e commit 0ad109a

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

.github/workflows/test-python.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
datetimes
7777
db_functions
7878
empty
79+
expressions.tests.NegatedExpressionTests
7980
defer
8081
defer_regress
8182
from_db_value

django_mongodb/expressions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.db.models.expressions import Col, ExpressionWrapper, Value
1+
from django.db.models.expressions import Col, ExpressionWrapper, NegatedExpression, Value
22

33

44
def col(self, compiler, connection): # noqa: ARG001
@@ -9,11 +9,16 @@ def expression_wrapper(self, compiler, connection):
99
return self.expression.as_mql(compiler, connection)
1010

1111

12+
def negated_expression(self, compiler, connection):
13+
return {"$not": expression_wrapper(self, compiler, connection)}
14+
15+
1216
def value(self, compiler, connection): # noqa: ARG001
1317
return {"$literal": self.value}
1418

1519

1620
def register_expressions():
1721
Col.as_mql = col
1822
ExpressionWrapper.as_mql = expression_wrapper
23+
NegatedExpression.as_mql = negated_expression
1924
Value.as_mql = value

django_mongodb/features.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
197197
"annotations.tests.AliasTests.test_order_by_alias",
198198
"annotations.tests.NonAggregateAnnotationTestCase.test_order_by_aggregate",
199199
"annotations.tests.NonAggregateAnnotationTestCase.test_order_by_annotation",
200+
"expressions.tests.NegatedExpressionTests.test_filter",
200201
# annotate().filter().count() gives incorrect results.
201202
"db_functions.datetime.test_extract_trunc.DateFunctionTests.test_extract_year_exact_lookup",
202203
},

0 commit comments

Comments
 (0)