On 10/30/07, Ben <[EMAIL PROTECTED]> wrote:
> I don't specifically need the before value, I need to know which of
> the fields have changed.
Okay, well, it still raises the same question, anyway.
But, regardless, you pretty much have two options:
- Store the values when the object is instantiated, and check those
when it's saved
- Perform a second query just before saving
It'd look something like this (untested code, beware):
class MyModel(models.Model):
spam = models.TextField(maxlength=255)
eggs = models.IntegerField()
def __init__(self, *args, **kwargs):
super(MyModel, self).__init__(*args, **kwargs)
self.__orig = {}
for field in MyModel._meta.fields:
self.__orig[field.name] = getattr(self, field.name)
def save(self):
_changed = []
for field in MyModel._meta.fields:
if self.__orig[field.name] != getattr(self, field.name):
_changed.append(field.name)
# Do something with _changed
# It's a list of field names whose values have changed
super(MyModel, self).save()
That's the basic idea, anyway. Hope this helps.
-Gul
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---