You can simply override the __init__ method and take a copy of the
values then:

See Malcolm's explanation here:
http://groups.google.com/group/django-users/msg/6d849eca95243371

-Mike

On Aug 30, 5:28 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> I tried using the signals... but setting a new value on the record,
> seems to also set it on the _original_data ...which is odd...maybe I'm
> not seeing something stupid that I'm doing?  If I change my
> marketing_status_name data in my view and save, the new data is in
> both the _original_data, and in the new property value.
>
> # some extra properties removed to make it shorter to read
> from django.db.models import signals
> from django.dispatch import dispatcher
> from django.db import models
>
> def backup_model_data(sender, instance, signal, *args, **kwargs):
>      instance._original_data = instance.__dict__.copy()
>
> class MarketingStatus(models.Model):
>     marketing_status_id = models.AutoField(primary_key=True)
>     marketing_status_name = models.CharField(blank=True, maxlength=30)
>     marketing_status_description = models.CharField(blank=True,
> maxlength=255)
>
>     def save(self):
>                         testing =
> self._original_data['marketing_status_name']
>                         testing2 = self.marketing_status_name
>
>                         triggererror = madeupvariabletotriggererror #
> just stuck this here so I can view the data in the browser
>
>                         super(MarketingStatus, self).save()
>
>     class Meta:
>         db_table = 'marketing_status'
>
> dispatcher.connect(backup_model_data,signal=signals.post_init,sender=MarketingStatus)
>
> On Aug 29, 2:24 pm, Doug B <[EMAIL PROTECTED]> wrote:
>
> > You could probably use the post_init signal to make a copy of the
> > model values for comparison in your save method. I'm doing something
> > similar to create a special manager object each time a certain model
> > instance is created.
>
> > Something like this...
>
> > def backup_model_data(sender, instance, signal, *args, **kwargs):
> >      instance._original_data = instance.__dict__.copy()
>
> > class YourModel(model.Models):
> >     ...
> > dispatcher.connect(backup_model_data,signal=signals.post_init,
> > sender=YourModel)


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to