Skip to content

Commit

Permalink
fix: operator rename
Browse files Browse the repository at this point in the history
  • Loading branch information
gersmann committed Jan 20, 2024
1 parent 8a01d66 commit db89076
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions django_mongodb/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ class MongoRelatedIn(MongoIn):
class MongoEqualityComparison(MongoLookup):
"""MongoDB Query Node for LessThanOrEqual"""

operator: str
filter_operator: str

def __init__(
self, operator: LessThan | LessThanOrEqual | GreaterThan | GreaterThanOrEqual, mongo_meta
):
super().__init__(operator, mongo_meta)
self.operator = {
self.filter_operator = {
LessThan: "$lt",
LessThanOrEqual: "$lte",
GreaterThan: "$gt",
Expand Down
12 changes: 12 additions & 0 deletions test/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest
from bson import ObjectId
from django.contrib.postgres.search import SearchQuery, SearchVector
from django.utils.timezone import now

from refapp.models import RefModel
from testapp.models import (
Expand Down Expand Up @@ -61,6 +62,17 @@ def test_mongo_emtpy():
assert len(list(FooModel.objects.none())) == 0


@pytest.mark.django_db(databases=["mongodb"])
def test_mongo_lookup():
FooModel.objects.all().delete()

FooModel.objects.create(name="test", json_field={"foo": "bar"})
FooModel.objects.create(name="test2", json_field={"foo": "bar"})

assert len(list(FooModel.objects.filter(datetime_field__lt=now()))) == 2
assert len(list(FooModel.objects.filter(name="test"))) == 1


@pytest.mark.django_db(databases=["mongodb"])
def test_mongo_model_filter_delete():
FooModel.objects.all().delete()
Expand Down

0 comments on commit db89076

Please sign in to comment.