Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #4415 -- Added formfield method to PositiveIntegerField, so tha…

…t those fields get validated correctly. Thanks, Oggie Rob.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6252 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit cf3c94b26dc76ee5493c206d64f5095b994afd63 1 parent ce53de4
@freakboy3742 freakboy3742 authored
View
10 django/db/models/fields/__init__.py
@@ -912,11 +912,21 @@ def formfield(self, **kwargs):
class PositiveIntegerField(IntegerField):
def get_manipulator_field_objs(self):
return [oldforms.PositiveIntegerField]
+
+ def formfield(self, **kwargs):
+ defaults = {'min_value': 0}
+ defaults.update(kwargs)
+ return super(PositiveIntegerField, self).formfield(**defaults)
class PositiveSmallIntegerField(IntegerField):
def get_manipulator_field_objs(self):
return [oldforms.PositiveSmallIntegerField]
+ def formfield(self, **kwargs):
+ defaults = {'min_value': 0}
+ defaults.update(kwargs)
+ return super(PositiveSmallIntegerField, self).formfield(**defaults)
+
class SlugField(CharField):
def __init__(self, *args, **kwargs):
kwargs['max_length'] = kwargs.get('max_length', 50)
View
21 tests/regressiontests/forms/models.py
@@ -0,0 +1,21 @@
+from django.db import models
+
+class BoundaryModel(models.Model):
+ positive_integer = models.PositiveIntegerField(null=True, blank=True)
+
+__test__ = {'API_TESTS': """
+>>> from django.newforms import form_for_model
+
+# Boundary conditions on a PostitiveIntegerField #########################
+>>> BoundaryForm = form_for_model(BoundaryModel)
+>>> f = BoundaryForm({'positive_integer':100})
+>>> f.is_valid()
+True
+>>> f = BoundaryForm({'positive_integer':0})
+>>> f.is_valid()
+True
+>>> f = BoundaryForm({'positive_integer':-100})
+>>> f.is_valid()
+False
+
+"""}
Please sign in to comment.
Something went wrong with that request. Please try again.