On Oct 7, 2:14 pm, Nan <[email protected]> wrote:
> class Foo(models.Model):
> bar = models.IntegerField()
>
> def save(self, force_insert=False, force_update=False):
> if self.id:
> # this is an update rather than a new instance
> old = Foo.objects.get(pk=self.id)
> # DO STUFF
> super(Foo, self).save(force_insert, force_update)
Oh, so I'm actually able to get the old value of the field after all:
def save(self, force_insert=False, force_update=False):
if self.id:
# this is an update rather than a new instance
old = Foo.objects.get(pk=self.id)
old_field = old.field_that_i_want
new_field = self.field_that_i_want
# Do something with old_field and new_field
super(Foo, self).save(force_insert, force_update)
Thanks. :)
Would this also work in pre_save or post_save signals, or only in the
model's save method?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---