On Jul 21, 7:52 pm, "Andre Meyer" <[EMAIL PROTECTED]> wrote:
> hi again
>
> so, auto_now is deprecated and can be replaced by overriding the
> save()method. but what about
> auto_now_add?
>
> how to distinguish between creation and update in save()???
>

You can tell whether or not it's a new object by checking to see if it
has an id. New objects don't get an id until they've been saved to the
database, so if it has one, you can tell it's an update.

def save(self):
    if self.id:
        # it's an update...
        self.modified = datetime.datetime.now()
    else:
        # it's a new object
        self.created = datetime.datetime.now()
    super(Foo, self).save()

--
DR.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to