Andrew Godwin  committed ab21b72

Fixed #1012: Errors with timezones and one-time defaults

  • Participants
  • Parent commits 286a7b6

Comments (0)

Files changed (2)

File south/creator/

 from django.db.models.fields.related import RECURSIVE_RELATIONSHIP_CONSTANT
 from django.db.models.fields import FieldDoesNotExist, NOT_PROVIDED, CharField, TextField
-from south import modelsinspector
+from south.modelsinspector import value_clean
 from south.creator.freezer import remove_useless_attributes, model_key
 from south.utils import datetime_utils
 class Action(object):
     Generic base Action class. Contains utility methods for inserting into
         # Right, add the default in.
-        field_def[2]['default'] = repr(result)
+        field_def[2]['default'] = value_clean(result)
     def irreversable_code(self, field):
         return self.IRREVERSIBLE_TEMPLATE % {

File south/

         default_value = format % tuple(map(lambda x: get_attribute(field, x), attrs))
         if value == default_value:
             raise IsDefault
+    # Clean and return the value
+    return value_clean(value, options)
+def value_clean(value, options={}):
+    "Takes a value and cleans it up (so e.g. it has timezone working right)"
+    # Lazy-eval functions get eval'd.
+    if isinstance(value, Promise):
+        value = unicode(value)
     # Callables get called.
     if callable(value) and not isinstance(value, ModelBase):
         # is special, as we can access it from the eval