Re: Any way to know if a value has changed before saving?

2008-01-31 Thread Alex Koshelev
def save( self ): if self._get_pk_val(): old = MyModel.objects.get( pk = self._get_pk_val() ) if self.field != old.field: print "Values do not match" super( MyModel, self ).save() On 31 янв, 10:54, Julien <[EMAIL PROTECTED]> wrote: > Hi there, > > I'd like to ove

Re: Any way to know if a value has changed before saving?

2008-01-31 Thread Michael Elsdörfer
> I'd like to override the save() method and within it I'd like to test > if a value has changed, that is, if that value as stored in the > object (in memory) is different from what is actually stored in > database. Another approach is using __getattr__ to monitor changes. It saves you a qu

Re: Any way to know if a value has changed before saving?

2008-01-31 Thread Julien
Yep, I should have thought of that. Cheers! On Jan 31, 7:13 pm, Ivan Illarionov <[EMAIL PROTECTED]> wrote: > > def save(self): > > if self.stuff != > > magic_function_that_tells_what_is_in_database_for('stuff') > > do_this() > > super(A, self).save() > > This 'magic function' is >

Re: Any way to know if a value has changed before saving?

2008-01-31 Thread Ivan Illarionov
> def save(self): > if self.stuff != > magic_function_that_tells_what_is_in_database_for('stuff') > do_this() > super(A, self).save() This 'magic function' is self.__class__.objects.get(id=self.id).stuff if self.stuff != self.__class__.objects.get(id=self.id).stuff: do_this()

Any way to know if a value has changed before saving?

2008-01-30 Thread Julien
Hi there, I'd like to override the save() method and within it I'd like to test if a value has changed, that is, if that value as stored in the object (in memory) is different from what is actually stored in database. Something like: class A: stuff = models.blabla def save(self): if sel