Django uses Model.clean for custom Model validation.
[cookbook.git] / cookbook / models.py
index 072647602421caa84674676c1bc2a4af11fc49c8..cfad7b588687259b968cc7ad87530502b5fdb41a 100644 (file)
@@ -84,7 +84,7 @@ class Amount (models.Model):
                     fmt = u'{0.value} ({0.min_value}-{0.max_value}) {0.unit}'
         return fmt.format(self)
 
-    def validate_amount(self):
+    def clean(self):
         if self.value is None:
             if self.min_value is None and self.max_value is not None:
                 raise ValidationError('cannot only set max_value')
@@ -92,6 +92,7 @@ class Amount (models.Model):
                 raise ValidationError('cannot only set min_value')
         if self.value is not None and self.unit is None:
             raise ValidationError('values must have units')
+        super(Amount, self).clean()
 
 
 class Directions (models.Model):