r_f_d wrote: > As far as insert or update, just overide the save method within the > class. It is something that must be done for each class, but what I > have done (for essentially the same purpose) is override save() on > each model I need to log the action for like so: > > def save(): > # if id exists, this record has already been created > if foo.id: > # create the log entry for an update > else: > # create the log entry for an insert > super(foo, self).save() >
This part is not entirely correct. Yes, it's true that if self.id (or whatever the primary key is) does not exist, then it's a create. However, just because self.id exists does not mean that it's an update. The Model class has a mechanism in save() that checks to make sure that the primary key exists in the DB. If it doesn't, it will do a create. Unfortunately, as it currently stands there's no way to distinguish this case without doing the SELECT on the PK yourself (the query or its results aren't accessible to user code in any way right now), which is why I recommended the post_save signal pending Trac ticket #4879's acceptance. gav --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---