def test_transform(self): try: DecimalField.register_lookup(Round) DecimalModel.objects.create(n1=Decimal('2.0'), n2=Decimal('0')) DecimalModel.objects.create(n1=Decimal('-1.0'), n2=Decimal('0')) objs = DecimalModel.objects.filter(n1__round__gt=0) self.assertQuerysetEqual(objs, [Decimal('2.0')], lambda a: a.n1) finally: DecimalField._unregister_lookup(Round)
def test_transform(self): try: DecimalField.register_lookup(ACos) DecimalModel.objects.create(n1=Decimal('0.5'), n2=Decimal('0')) DecimalModel.objects.create(n1=Decimal('-0.9'), n2=Decimal('0')) objs = DecimalModel.objects.filter(n1__acos__lt=2) self.assertQuerysetEqual(objs, [Decimal('0.5')], lambda a: a.n1) finally: DecimalField._unregister_lookup(ACos)
def test_transform(self): try: DecimalField.register_lookup(Floor) DecimalModel.objects.create(n1=Decimal('5.4'), n2=Decimal('0')) DecimalModel.objects.create(n1=Decimal('3.4'), n2=Decimal('0')) objs = DecimalModel.objects.filter(n1__floor__gt=4) self.assertQuerysetEqual(objs, [Decimal('5.4')], lambda a: a.n1) finally: DecimalField._unregister_lookup(Floor)
def test_transform(self): try: DecimalField.register_lookup(Ceil) DecimalModel.objects.create(n1=Decimal('3.12'), n2=Decimal('0')) DecimalModel.objects.create(n1=Decimal('1.25'), n2=Decimal('0')) objs = DecimalModel.objects.filter(n1__ceil__gt=3) self.assertQuerysetEqual(objs, [Decimal('3.12')], lambda a: a.n1) finally: DecimalField._unregister_lookup(Ceil)
def test_transform(self): try: DecimalField.register_lookup(Cos) DecimalModel.objects.create(n1=Decimal('-8.0'), n2=Decimal('0')) DecimalModel.objects.create(n1=Decimal('3.14'), n2=Decimal('0')) objs = DecimalModel.objects.filter(n1__cos__gt=-0.2) self.assertQuerysetEqual(objs, [Decimal('-8.0')], lambda a: a.n1) finally: DecimalField._unregister_lookup(Cos)