For what it's worth, I can imagine on way of doing this. I could use
signals to monkeypatch the instance at post_init, adding an attribute
called "post_init_status." Then I could compare this value with
"status" at post_save.

Please save me from doing something so ugly.

On Mar 6, 12:28 am, Rama Vadakattu <[email protected]> wrote:
> So you need to trigger an action the first time you save an object in
> to the database.
>
> ----------------------
>
> Class A:
>
>    #self.id is None whenever a particular instance has not been saved
> into a database
>
>    #override save method in the object as follows
>
>    def save(self) :
>        firstime = false
>
>        if ~self.id :
>            firsttime = true
>
>        super.save()
>
>        #this code only fires only when it is being saved for the first
> time.
>        if firstime :
>           #Trigger an action whichevery you want.................
>
> ---------------------------------
>
> Hope the above code helps you in resolving the problem.
>
> On Mar 6, 11:02 am, "[email protected]" <[email protected]> wrote:
>
> > Sorry for the unwieldy title, but nothing else strikes me at the
> > moment.
>
> > I have a blog app -- a version of basic.blog, actually. There's a
> > field in the model called "status" with two options: "draft" and
> > "public."
>
> > What I want to do is trigger an action the first time (and /only/ the
> > first time) a particular instance is saved as "public."
>
> > So:
>
> > Write a post in the admin, save as draft --> No action
> > Edit the post some, save as draft again --> No action
> > Edit more, publish                               --> Action triggered!
> > Edit again                                           --> No action.
>
> > How would I go about this? My thought is to override save(), but I
> > can't figure out how to inspect the instance at that point to
> > determine if the status attribute has changed since it was created. I
> > assume that this information must be in there somewhere, since it
> > seems like you'd need it to generate the SQL statement.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to