Friday, September 17, 2010

Re: tracking changes of a model's attributes

just an idea - use database triggers

On Sep 17, 12:53 pm, Julian <maili...@julianmoritz.de> wrote:
> hi,
>
> i'm writing a little statistical app for a django-project. everytime a
> very model is saved, something's stored in the db, depending on the
> model's attributes. if one of the attributes changes, I have to change
> the statisitical data otherwise it would leed to inconsistency. I need
> to know the old value of the attribute. how do I get it?
>
> for example: I have a model
>
> class AModel(models.Model):
>     a = models.CharField(...)
>
> class StatisticModel(models.Model):
>     a_value = models.CharField(...)
>     a_counter = mdoels.IntegerField(...)
>
> on post_save() of a = AModel(a='a') I select the StatisticModel with
> a_value = 'a' and increase a_counter by 1. If then a is saved again
> with a = 'b', I have to decrease a_counter of the StatisticModel with
> a_value = 'a' by 1 and increase it by 1 on another instance.
>
> How can I do this?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate