Ticket #11007: modelchanges.patch

File modelchanges.patch, 848 bytes (added by dennis@…, 16 years ago)
  • django/db/models/base.py

     
    593593
    594594    def prepare_database_save(self, unused):
    595595        return self.pk
     596   
     597    def changes(self):
     598        fields = [x.name for x in self._meta._fields() if not (x.name.endswith('_ptr_id') or x.name.endswith('_ptr'))]
     599        if not self.pk:
     600            return dict([(x, (None, getattr(self, x))) for x in fields])
     601        old = self.__class__.objects.get(pk=self.pk)
     602        return dict([(x, (getattr(old, x), getattr(self, x))) for x in fields if getattr(self, x) != getattr(old, x)])
    596603
    597 
    598604############################################
    599605# HELPER FUNCTIONS (CURRIED MODEL METHODS) #
    600606############################################
Back to Top