Ticket #4415: positiveintegerfield2.diff
File positiveintegerfield2.diff, 957 bytes (added by , 17 years ago) |
---|
-
django/newforms/fields.py
139 139 raise ValidationError(ugettext(u'Ensure this value is greater than or equal to %s.') % self.min_value) 140 140 return value 141 141 142 class PositiveIntegerField(forms.IntegerField): 143 def clean(self, value): 144 """ 145 Validates that the value is positive. 146 Returns the result of int(). Returns None for empty values. 147 """ 148 value = super(PositiveIntegerField, self).clean(value) 149 if value is not None and value < 0: 150 raise forms.ValidationError(ugettext(u'Ensure this number is positive.')) 151 return value 152 142 153 class FloatField(Field): 143 154 def __init__(self, max_value=None, min_value=None, *args, **kwargs): 144 155 self.max_value, self.min_value = max_value, min_value