Ticket #5079: 5079.diff

File 5079.diff, 1.1 KB (added by Philippe Raoult, 17 years ago)

added regression tests for DecimalField

  • tests/modeltests/basic/models.py

     
    66"""
    77
    88from django.db import models
     9from decimal import Decimal
    910
    1011class Article(models.Model):
    1112    headline = models.CharField(max_length=100, default='Default headline')
     
    1718    def __unicode__(self):
    1819        return self.headline
    1920
     21class DecimalTest(models.Model):
     22    field = models.DecimalField(max_digits=40, decimal_places=1)
     23   
    2024__test__ = {'API_TESTS': """
     25>>> b1 = DecimalTest(field=Decimal(".1"))
     26>>> b1.field
     27Decimal("0.1")
     28>>> b1.save()
     29>>> b1.field
     30Decimal("0.1")
     31>>> b1 = DecimalTest.objects.get(id=1)
     32>>> b1.field
     33Decimal("0.1")
     34>>> b1.field = Decimal(".14")
     35
     36# the value is still .14 before saving
     37>>> b1.field
     38Decimal("0.14")
     39>>> b1.save()
     40
     41# but when we save/retrieve from the DB the constraints have been applied
     42>>> b1 = DecimalTest.objects.get(id=1)
     43>>> b1.field
     44Decimal("0.1")
     45
    2146# No articles are in the system yet.
    2247>>> Article.objects.all()
    2348[]
Back to Top