Commits

Anonymous committed de0465f

remove previous_status from StatusField public API

I may be missing the use case, but this seems too ephemeral to be
useful (only exists on same instance after a save, can't rely on it
being there in general). If it's just an implementation detail for
StatusModifiedField, it doesn't need to be tested in public API for
StatusField.

Comments (0)

Files changed (2)

model_utils/fields.py

         return None
     return getattr(current, attname, None)
 
+
 class StatusField(models.CharField):
     """
     A CharField that has set status choices by default.
     def contribute_to_class(self, cls, name):
         if not cls._meta.abstract:
             assert hasattr(cls, 'STATUS'), \
-                "The model '%s' doesn't have status choices." % cls.__name__
+                "To use StatusField, the model '%s' must have a STATUS choices attribute." \
+                % cls.__name__
             setattr(self, '_choices', cls.STATUS)
             setattr(self, 'default', tuple(cls.STATUS)[0][0]) # sets first as default
         super(StatusField, self).contribute_to_class(cls, name)
 
-    def pre_save(self, model_instance, add):
-        previous = _previous_status(model_instance, 'get_%s_display' % self.attname, add)
-        if previous:
-            previous = previous()
-        setattr(model_instance, 'previous_status', previous)
-        return super(StatusField, self).pre_save(model_instance, add)
 
 class StatusModifiedField(models.DateTimeField):
 

model_utils/tests/tests.py

         t1.save()
         self.assert_(t1.status_date > date_active_again)
 
-    def testPreviousConditon(self):
-        status = self.model.objects.create()
-        self.assertEquals(status.previous_status, None)
-        status.status = status.STATUS.on_hold
-        status.save()
-        self.assertEquals(status.previous_status, status.STATUS.active)
-
+        
 class Status2ModelTests(StatusModelTests):
     def setUp(self):
         self.model = Status2
         t1.save()
         self.assert_(t1.status_date > date_active_again)
 
-    def testPreviousConditon(self):
-        status = self.model.objects.create()
-        self.assertEquals(status.previous_status, None)
-        status.status = status.STATUS[2][0]
-        status.save()
-        self.assertEquals(status.previous_status, status.STATUS[0][0])
 
 class QueryManagerTests(TestCase):
     def setUp(self):