Probably you want to do that logic a slightly differently on a model level
(so rule would apply always when you save your model).

So you would actually override model save method.

Probably rule is something like this:

class MyPublicationModel(Model):
    def save(...):  # I don't remember the signature
        if self.is_published and not self.publication_date:
            # Published previously unpublished - set the date
            self.publication_date = date.today()
       elif not self.is_published and self.publication_date:
            # Mark already published as unpublished - clear the date
            self.publication_date = None

       super(self, MyPublicationModel).save(...)

On Mon, Jul 16, 2012 at 3:39 AM, Nicolas Emiliani <or3s...@gmail.com> wrote:

>
>
> On Sun, Jul 15, 2012 at 8:10 PM, Jani Tiainen <rede...@gmail.com> wrote:
>
>> Hi,
>>
>> How about telling us what are you trying to achieve by comparing to
>> previous state of the object?
>>
>>
> Well, the model has a boolean field called published, and a publish_date
> that gets set "automatically"
> when the user through the admin panel sets the flag published to true. He
> could also unpublish it, but the
> date would still remain the same (on the date it was first published). And
> here comes the problem :
>
> If the user decides to republish I would have to set the date to current
> date, but how do I know if he
> is republishing or he modified some other field that has nothing to do
> with that attribute ? I would be
> republishing only if it's previous state was not published. But how can I
> acces that previous state ?
>
> Sounds waky :P
>
>
>
>> On Sun, Jul 15, 2012 at 1:49 AM, Nicolas Emiliani <or3s...@gmail.com>wrote:
>>
>>> Hi,
>>>
>>> Is there a way to access the state of a Model object prior to it's
>>> modification through a form ?
>>> Kind of a nasty question :S, let me explain.
>>>
>>> The thing is that if i use the save_model hook and the user modifies the
>>> model through the form,
>>> the obj parameter that I receive has already all the modifications
>>> loaded, so if  I have, let's say,
>>> a boolean attribute called "published"  and the user clicked published
>>> then :
>>>
>>> obj.published == True
>>>
>>> Is there a way to know which was the state of the model, in this case
>>> the state of obj.published,
>>> before the user clicked on the save button on the admin form ? or should
>>> I use a second model
>>> attribute and hide it on the form to keep the previous state ? is there
>>> a "Django" way to do this ?
>>>
>>> It's my first post, be gentle :P
>>>
>>> Thanks !
>>>
>>> --
>>> Nicolas Emiliani
>>>
>>> Lo unico instantaneo en la vida es el cafe, y es bien feo.
>>>
>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>
>>
>>
>> --
>> Jani Tiainen
>>
>> - Well planned is half done, and a half done has been sufficient before...
>>
>>  --
>> 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+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> --
> Nicolas Emiliani
>
> Lo unico instantaneo en la vida es el cafe, y es bien feo.
>
> --
> 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+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to