Friday, February 4, 2011

Re: How to know if is a update or insert??

On Fri, Feb 4, 2011 at 10:13 PM, andmart <andmart@gmail.com> wrote:
> Hi,
>
> I overrided the save_model of ModelAdmin of model Client that is
> associated a one User so I can create a user when a client is created.
>
> Well, how to know if the save_model was called to do a update or a
> insert if the object already exists in database?
>
> Trying to see if model.pk exists fail.

Hi, I've never had problemas with:

def save(self, *args....):
if self.pk:
#update
else:
#insert

this is how you check if model.pk exists?

--
Marc

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

No comments:

Post a Comment