Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Russell Keith-Magee authored
10  django/db/models/fields/__init__.py
@@ -912,11 +912,21 @@ def formfield(self, **kwargs):
912 912
 class PositiveIntegerField(IntegerField):
913 913
     def get_manipulator_field_objs(self):
914 914
         return [oldforms.PositiveIntegerField]
  915
+    
  916
+    def formfield(self, **kwargs):
  917
+        defaults = {'min_value': 0}
  918
+        defaults.update(kwargs)
  919
+        return super(PositiveIntegerField, self).formfield(**defaults) 
915 920
 
916 921
 class PositiveSmallIntegerField(IntegerField):
917 922
     def get_manipulator_field_objs(self):
918 923
         return [oldforms.PositiveSmallIntegerField]
919 924
 
  925
+    def formfield(self, **kwargs):
  926
+        defaults = {'min_value': 0}
  927
+        defaults.update(kwargs)
  928
+        return super(PositiveSmallIntegerField, self).formfield(**defaults) 
  929
+
920 930
 class SlugField(CharField):
921 931
     def __init__(self, *args, **kwargs):
922 932
         kwargs['max_length'] = kwargs.get('max_length', 50)
21  tests/regressiontests/forms/models.py
... ...
@@ -0,0 +1,21 @@
  1
+from django.db import models
  2
+
  3
+class BoundaryModel(models.Model): 
  4
+    positive_integer = models.PositiveIntegerField(null=True, blank=True)
  5
+    
  6
+__test__ = {'API_TESTS': """
  7
+>>> from django.newforms import form_for_model
  8
+
  9
+# Boundary conditions on a PostitiveIntegerField #########################
  10
+>>> BoundaryForm = form_for_model(BoundaryModel) 
  11
+>>> f = BoundaryForm({'positive_integer':100}) 
  12
+>>> f.is_valid() 
  13
+True
  14
+>>> f = BoundaryForm({'positive_integer':0}) 
  15
+>>> f.is_valid() 
  16
+True
  17
+>>> f = BoundaryForm({'positive_integer':-100}) 
  18
+>>> f.is_valid() 
  19
+False
  20
+
  21
+"""}

0 notes on commit cf3c94b

Please sign in to comment.
Something went wrong with that request. Please try again.