From 6b5bd3fe45e54597fbc7ddbc550a9a20b7d339e2 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Wed, 6 Dec 2017 21:14:14 +0100 Subject: [PATCH] only allow positiv prices In order to only allow positiv prices I had import two new classes. --- django/didgeridoo/webshop/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/django/didgeridoo/webshop/models.py b/django/didgeridoo/webshop/models.py index 72f296e..c729f65 100644 --- a/django/didgeridoo/webshop/models.py +++ b/django/didgeridoo/webshop/models.py @@ -1,5 +1,7 @@ #!/usr/bin/python3 +from decimal import Decimal +from django.core.validators import MinValueValidator from django.db import models from django.contrib.auth.models import User @@ -53,7 +55,10 @@ class Article(models.Model): description = models.TextField(max_length=2000) stock = models.FloatField(max_length=5) status = models.ForeignKey(ArticleStatus) - price_in_chf = models.DecimalField(max_digits=19, decimal_places=2) + price_in_chf = models.DecimalField(max_digits=19, + decimal_places=2, + validators=[MinValueValidator( + Decimal('0.00'))]) def __str__(self): return self.name