Commits

James Crasta committed ea5b374

NullBoolean converter didn't work. Now it works.

  • Participants
  • Parent commits 546d044

Comments (0)

Files changed (3)

File tests/ext_django/models.py

     bool     = models.BooleanField()
     time1    = models.TimeField()
     slug     = models.SlugField()
+    nullbool = models.NullBooleanField()
 

File tests/ext_django/tests.py

 
     def test_form_sanity(self):
         self.assertEqual(self.F.__name__, 'UserForm')
-        self.assertEqual(len([x for x in self.form]), 13)
-        self.assertEqual(len([x for x in self.form_with_pk]), 14)
+        self.assertEqual(len([x for x in self.form]), 14)
+        self.assertEqual(len([x for x in self.form_with_pk]), 15)
 
     def test_label(self):
         self.assertEqual(self.form.reg_ip.label.text, 'IP Addy')
         self.assertTrue(contains_validator(self.form.posts, validators.NumberRange))
         self.assertEqual(self.form.posts.description, 'Test')
 
+    def test_nullbool(self):
+        field = self.form.nullbool
+        assert isinstance(field, fields.SelectField)
+        self.assertEqual(len(field.choices), 3)
+
 class QuerySetSelectFieldTest(DjangoTestCase):
     fixtures = ['ext_django.json']
 

File wtforms/ext/django/orm.py

         return f.TextField(**kwargs)
 
     def conv_NullBooleanField(self, model, field, kwargs):
+        from django.db.models.fields import NOT_PROVIDED
         def coerce_nullbool(value):
             d = {'None': None, None: None, 'True': True, 'False': False}
-            if value in d:
+            if isinstance(value, NOT_PROVIDED):
+                return None
+            elif value in d:
                 return d[value]
             else:
                 return bool(int(value))