Commits

Matthew Schinckel committed d5d1846

Handle nullable fields better.

Comments (0)

Files changed (1)

colour_field/fields.py

         return value
     
     def get_prep_value(self, value):
-        if not value.strip() and self.null:
+        if not (value and value.strip()) and self.null:
             return None
         return value
     
     def value_to_string(self, value):
-        return value.strip() or None
+        if value:
+            return value.strip() or None
         
     def formfield(self, *args, **kwargs):
         defaults = {'form_class': ColourFormField}
         return super(ColourField, self).formfield(*args, **defaults)
     
     def db_type(self, connection):
-        return 'char(7)'
+        return 'char(7)'