transaction: change "minValue('0')" to "notZero"

This commit is contained in:
Sebastian Lohff 2011-10-25 20:17:38 +02:00
parent f432ffc70b
commit 38068e1ebb
2 changed files with 9 additions and 1 deletions

View File

@ -6,6 +6,7 @@ from django.db.models.deletion import SET_NULL
from django.db.models.signals import pre_delete from django.db.models.signals import pre_delete
from decimal import Decimal from decimal import Decimal
from validator import validate_notZero
class TransactionType(models.Model): class TransactionType(models.Model):
""" Type for a :class:`Transaction`. States how the money has """ Type for a :class:`Transaction`. States how the money has
@ -22,7 +23,7 @@ class Transaction(models.Model):
user = models.ForeignKey(User) user = models.ForeignKey(User)
transactionType = models.ForeignKey(TransactionType, verbose_name='Typ') transactionType = models.ForeignKey(TransactionType, verbose_name='Typ')
dateTime = models.DateTimeField(auto_now_add=True) dateTime = models.DateTimeField(auto_now_add=True)
amount = models.DecimalField(max_digits=8, decimal_places=2, validators=[MinValueValidator(Decimal("0.01"))]) amount = models.DecimalField(max_digits=8, decimal_places=2, validators=[validate_notZero])
checked = models.BooleanField(default=False) checked = models.BooleanField(default=False)

View File

@ -0,0 +1,7 @@
from django.core.exceptions import ValidationError
from decimal import Decimal
def validate_notZero(value):
if value == Decimal("0.0") :
raise ValidationError(u'%s is not an real number\{0.00}' % value)