Re: custom action during "insert" but not during "update"

2008-06-07 Thread chefsmart

Alex, Julien

That was it  -- thanks.

On Jun 8, 10:37 am, Julien <[EMAIL PROTECTED]> wrote:
> As alex says, testing the primary is the only way that I know of:
>
> def save(self):
>     if self.pk is None:
>         # Here's we're creating a new object
>     else:
>         # Here we're updating an existing object
>
> On Jun 8, 2:53 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>
> > If you overide model.save() just check for self.pk to be set.
>
> > On Jun 7, 11:19 pm, chefsmart <[EMAIL PROTECTED]> wrote:
>
> > > Hi All,
>
> > > I need some insight on the following scenario:
>
> > > I want to execute some custom action when creating new model instances
> > > when calling model.save(), but I don't want this custom action to
> > > execute when updating an existing model instance.
>
> > > How do I distinguish between an "insert" and an "update" as django
> > > uses save() for both?
>
> > > 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: custom action during "insert" but not during "update"

2008-06-07 Thread Julien

As alex says, testing the primary is the only way that I know of:

def save(self):
if self.pk is None:
# Here's we're creating a new object
else:
# Here we're updating an existing object


On Jun 8, 2:53 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> If you overide model.save() just check for self.pk to be set.
>
> On Jun 7, 11:19 pm, chefsmart <[EMAIL PROTECTED]> wrote:
>
> > Hi All,
>
> > I need some insight on the following scenario:
>
> > I want to execute some custom action when creating new model instances
> > when calling model.save(), but I don't want this custom action to
> > execute when updating an existing model instance.
>
> > How do I distinguish between an "insert" and an "update" as django
> > uses save() for both?
>
> > 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: custom action during "insert" but not during "update"

2008-06-07 Thread [EMAIL PROTECTED]

If you overide model.save() just check for self.pk to be set.

On Jun 7, 11:19 pm, chefsmart <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I need some insight on the following scenario:
>
> I want to execute some custom action when creating new model instances
> when calling model.save(), but I don't want this custom action to
> execute when updating an existing model instance.
>
> How do I distinguish between an "insert" and an "update" as django
> uses save() for both?
>
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---