diff --git a/django_mongodb/query.py b/django_mongodb/query.py index 03e5cf9..bf36a98 100644 --- a/django_mongodb/query.py +++ b/django_mongodb/query.py @@ -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", diff --git a/test/test_models.py b/test/test_models.py index 9406fd2..b397d8a 100644 --- a/test/test_models.py +++ b/test/test_models.py @@ -1,10 +1,12 @@ import datetime import os import time +from datetime import timedelta 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 ( @@ -61,6 +63,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__gt=now() - timedelta(hours=1)))) == 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()