2 from django.db import models
3 from django.forms.models import model_to_dict
5 class PlCoreBase(models.Model):
7 created = models.DateTimeField(auto_now_add=True)
8 updated = models.DateTimeField(auto_now=True)
14 def __init__(self, *args, **kwargs):
15 super(PlCoreBase, self).__init__(*args, **kwargs)
16 self.__initial = self._dict
22 diffs = [(k, (v, d2[k])) for k, v in d1.items() if v != d2[k]]
26 def has_changed(self):
27 return bool(self.diff)
30 def changed_fields(self):
31 return self.diff.keys()
33 def get_field_diff(self, field_name):
34 return self.diff.get(field_name, None)
36 def save(self, *args, **kwargs):
37 super(PlCoreBase, self).save(*args, **kwargs)
38 self.__initial = self._dict
42 return model_to_dict(self, fields=[field.name for field in