On Fri, 2007-02-09 at 22:09 -0500, Benjamin Slavin wrote: > Howdy all, > > I was investigating post_save to perform some associated setup for an > object after it's created. My only concern is that I can't seem to > find any way to check if the object was created on this call to > save()... I only want to perform the setup the first time the object > is saved. > > So... Is it possible to perform a function (via post_save or some > other mechanism) when a given object is saved for the first time? > > Perhaps the addition of a post_create signal could be a solution, but > I didn't want to bring that up on django-developers until I asked > here.
Using the signal system might be overkill here. Can you achieve whatever you want with your own save() method (remember that you can then call the model's default save() method after doing your own stuff)? If you can do that, then a common way to check if the model is being created is to check the automatically created "id" (surrogate primary key) attribute. If it's empty, the model hasn't been saved yet (since it doesn't have a database-assigned primary key value). This doesn't work in cases where you manually assign the primary key value, but it is sufficient for many common uses. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---