Skip to content

Commit 921008f

Browse files
committed
Add __str__ method
1 parent ebc972b commit 921008f

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

django_mongodb_backend/expressions/builtins.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,11 @@ def __ror__(self, other):
263263
class SearchExpression(SearchCombinable, Expression):
264264
output_field = FloatField()
265265

266-
def get_source_expressions(self):
267-
return []
268-
269266
def __str__(self):
270-
args = ", ".join(map(str, self.get_source_expressions()))
271-
return f"{self.search_type}({args})"
267+
cls = self.identity[0]
268+
kwargs = dict(self.identity[1:])
269+
arg_str = ", ".join(f"{k}={v!r}" for k, v in kwargs.items())
270+
return f"{cls.__name__}({arg_str})"
272271

273272
def __repr__(self):
274273
return str(self)
@@ -316,8 +315,6 @@ def search_operator(self, compiler, connection):
316315

317316

318317
class SearchEquals(SearchExpression):
319-
search_type = "equals"
320-
321318
def __init__(self, path, value, score=None):
322319
self.path = path
323320
self.value = value
@@ -570,8 +567,6 @@ def get_search_fields(self):
570567

571568

572569
class SearchMoreLikeThis(SearchExpression):
573-
search_type = "more_like_this"
574-
575570
def __init__(self, documents, score=None):
576571
self.documents = documents
577572
self.score = score
@@ -648,8 +643,6 @@ def as_mql(self, compiler, connection):
648643

649644

650645
class CompoundExpression(SearchExpression):
651-
search_type = "compound"
652-
653646
def __init__(
654647
self,
655648
must=None,
@@ -698,8 +691,6 @@ def negate(self):
698691

699692

700693
class CombinedSearchExpression(SearchExpression):
701-
search_type = "combined"
702-
703694
def __init__(self, lhs, operator, rhs):
704695
self.lhs = lhs
705696
self.operator = operator

0 commit comments

Comments
 (0)