Refs #373, Refs #24121 -- Added ColPairs.__repr__().

This commit is contained in:
Bendeguz Csirmaz 2024-09-10 21:12:25 +08:00 committed by Sarah Boyce
parent ee5147cfd7
commit 9ca1f6eff6
2 changed files with 11 additions and 0 deletions

View File

@ -1342,6 +1342,12 @@ class ColPairs(Expression):
def __iter__(self): def __iter__(self):
return iter(self.get_cols()) return iter(self.get_cols())
def __repr__(self):
return (
f"{self.__class__.__name__}({self.alias!r}, {self.targets!r}, "
f"{self.sources!r}, {self.output_field!r})"
)
def get_cols(self): def get_cols(self):
return [ return [
Col(self.alias, target, source) Col(self.alias, target, source)

View File

@ -47,6 +47,7 @@ from django.db.models import (
) )
from django.db.models.expressions import ( from django.db.models.expressions import (
Col, Col,
ColPairs,
Combinable, Combinable,
CombinedExpression, CombinedExpression,
NegatedExpression, NegatedExpression,
@ -2466,6 +2467,10 @@ class ReprTests(SimpleTestCase):
"<When: WHEN <Q: (AND: ('age__gte', 18))> THEN Value('legal')>", "<When: WHEN <Q: (AND: ('age__gte', 18))> THEN Value('legal')>",
) )
self.assertEqual(repr(Col("alias", "field")), "Col(alias, field)") self.assertEqual(repr(Col("alias", "field")), "Col(alias, field)")
self.assertEqual(
repr(ColPairs("alias", ["t1", "t2"], ["s1", "s2"], "f")),
"ColPairs('alias', ['t1', 't2'], ['s1', 's2'], 'f')",
)
self.assertEqual(repr(F("published")), "F(published)") self.assertEqual(repr(F("published")), "F(published)")
self.assertEqual( self.assertEqual(
repr(F("cost") + F("tax")), "<CombinedExpression: F(cost) + F(tax)>" repr(F("cost") + F("tax")), "<CombinedExpression: F(cost) + F(tax)>"