hi Daniel
cool, thanks
in combination, now it looks like this:
class MyModel(models.Model):
created = models.DateTimeField()
modified = models.DateTimeField()
parent = models.ForeignKey('self', related_name='children', null=True,
blank=True)
def save(self, **kwargs):
now = datetime.now()
self.modified = now
if not self.id:
self.created = now
if self.parent:
self.parent.save(**kwargs)
super(MyModel, self).save(**kwargs)
cheers
André
On Mon, Jul 21, 2008 at 10:47 PM, Daniel Roseman <
[EMAIL PROTECTED]> wrote:
>
> 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
-~----------~----~----~----~------~----~------~--~---