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(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(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(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)
function = 'ABS' class State(models.Model): abbreviation = models.CharField(max_length=2, unique=False) name = models.CharField(max_length=25, unique=True) def __unicode__(self): return self.name class Candidate(models.Model): name = models.CharField(max_length=100) PARTY_CHOICES=( ('Democratic', 'Democratic'), ('Republican', 'Republican') ) party = models.CharField(max_length=15, choices=PARTY_CHOICES) def __unicode__(self): return self.name class Tweet(models.Model): text = models.CharField(max_length=155, blank=False, unique=True) author = models.CharField(max_length=100) sentiment = models.DecimalField(max_digits=5, decimal_places=2) state = models.ForeignKey(State) #state_id candidate = models.ForeignKey(Candidate) #candidate_id def __unicode__(self): return self.text DecimalField.register_lookup(AbsoluteValue)