Commits

Matthew Schinckel committed a033d0e

Force a save, just in case.
Store a None in the db instead of "" in some cases.

Comments (0)

Files changed (1)

rest_api/options.py

 from django.contrib.contenttypes.models import ContentType
 from django.utils.encoding import force_unicode
 from django.conf.urls.defaults import patterns, url
-        
+from django.forms import ValidationError
+
 from decorators import methods
 import http
 
         objects = self.model.objects.filter(pk__in=created)
         for obj in objects:
             self.log_addition(request, obj)
+            obj.save()
+            logging.debug("Updated at %s" % obj.updated_at)
         if len(objects):
             return http.Created(objects)
         return http.OK("Nothing created.")
                 # If this was an audit field, ignore it. We set these according to the user who ran the request.
                 if field.name == 'updated_by' or field.name == 'created_by':
                     continue
+                if not field.empty_strings_allowed and field.null and value == "":
+                    # I hate that django wants to store "" in the database
+                    # when I really mean None.
+                    setattr(instance, key, None)
+                    continue
                 if field.value_from_object(instance) != field.to_python(value):
                     # Do I need to serialize this?
                     if field.rel:
                     except AttributeError:
                         # Could not set this attribute: read-only?
                         pass
-        
+                
         instance.updated_by = request.user
         try:
             instance.save()
             message = "Changed %s." % ", ".join(["%s to %s" % x for x in changed.iteritems()])
             #TODO: instance should reflect the new values?
             self.log_change(request, instance, message)
+            logging.debug(message)
 
         return self.model._default_manager.filter(pk=pk)