1. Ian George
  2. django-statemachine

Commits

Ian George  committed ba081f4

Moved change_date from auto_now=True to being updated on save()

  • Participants
  • Parent commits c07e632
  • Branches default

Comments (0)

Files changed (1)

File statemachine/models.py

View file
  • Ignore whitespace
+from datetime import datetime
 from django.db import models
 from django.contrib.contenttypes.models import ContentType
 from django.contrib.contenttypes import generic
     # log of to / from, state info, date, user
     from_state = models.CharField(max_length=150, db_index=True)
     to_state = models.CharField(max_length=150, db_index=True)
-    change_date = models.DateTimeField(auto_now=True, db_index=True)
+    change_date = models.DateTimeField(db_index=True)
     user = models.ForeignKey(User, null=True, blank=True)
 
     #optional notes
     notes = models.CharField(max_length=500, null=True, blank=True)
 
+    def save(self, *args, **kwargs):
+        ''' On save, update timestamps, stopped using auto_now because I wanted it editable in admin '''
+        self.change_date = datetime.today()
+        return super(StateMachineHistory, self).save(*args, **kwargs)
+
 
 class StateMachineWithHistory(models.Model):
     """