Re: how to find if a record changed
i believe it does. you can override the "save" method of your model
like this:
from django.db import models
from datetime import datetime
# Create your models here.
class TestModel(models.Model):
first_field = models.CharField(max_length=255)
second_field = models.BooleanField()
updated_at = models.DateTimeField(default=datetime.now)
def save(self, *args, **kwargs):
if hasattr(self, 'id') and getattr(self, 'id') is not None:
self.updated_at = datetime.now()
super(TestModel, self).save(*args, **kwargs)
On Apr 17, 6:25 pm, Aref <arefnamm...@gmail.com> wrote:
> Hello,
>
> I have a text field which could be updated regularly and I want to
> automatically attach a date every time the record is updated--but only
> if the record is updated. Can this be done in django and how would I
> go about doing it.
> Thanks.
--
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