Ivan Zakrevsky  committed 49a40df

minor changes

  • Participants
  • Parent commits 67bb643

Comments (0)

Files changed (1)

File autumn/

     def __setattr__(self, name, value):
         """Records when fields have changed"""
-        cls_attr = getattr(type(self), name, None)
-        if cls_attr is not None:
-            if isinstance(cls_attr, (property, Relation)):
-                return object.__setattr__(self, name, value)
+        if hasattr(getattr(type(self), name, None), '__set__'):
+            return object.__setattr__(self, name, value)
         if name in self._meta.fields:
             value = data_registry.convert_to_python(type(self).qs.dialect(), self._meta.fields[name].type_code, value)
     def _set_defaults(self):
         """Sets attribute defaults based on ``defaults`` dict"""
         for k, v in list(getattr(self._meta, 'defaults', {}).items()):
-            if not getattr(self, k, None):
+            if getattr(self, k, None) is None:
                 if isinstance(v, collections.Callable):
-                    v = v()
+                    try:
+                        v(self, k)
+                    except TypeError:
+                        v = v()
                 setattr(self, k, v)
     def is_valid(self, exclude=(), fields=()):
     def _validate(self, exclude=(), fields=()):
         """Tests all ``validations``"""
+        self._set_defaults()
         self._errors = {}
         for key, validators in list(getattr(self._meta, 'validations', {}).items()):
             if key in exclude or (fields and key not in fields):
     def save(self, using=None):
         """Sets defaults, validates and inserts into or updates database"""
         using = using or self._meta.using
-        self._set_defaults()
         if not self.is_valid():
             raise self.ValidationError("Invalid data!")
         self._send_signal(signal='pre_save', update_fields=self._changed, using=using)