Awesome! No problem.

Karl Sutt


On Sat, May 12, 2012 at 12:35 PM, Alireza Savand
<alireza.sav...@gmail.com>wrote:

> Thank you very much Karl, it works!
>
>
> On Sat, May 12, 2012 at 3:13 PM, Karl Sutt <k...@sutt.ee> wrote:
>
>> Thanks. So, in onPreSave, you use kwargs['instance'], assuming it's the
>> instance before saving (which it is, not just in the "current" state). So
>> kwargs['instance'] in both handlers have the same state. If you want to get
>> the current state (the old state, so to speak), you should to something like
>>
>> sender.objects.get(id=kwargs['instance'].id)
>>
>>
>> This would get you the current state of the that instance.
>>
>> Hope this is clear and helps.
>>
>> Karl Sutt
>>
>>
>>
>> On Sat, May 12, 2012 at 12:00 PM, Alireza Savand <
>> alireza.sav...@gmail.com> wrote:
>>
>>> Okay
>>> here the paste
>>> http://dpaste.de/Oa9cM/
>>> And the Model is just *Poll model* from the tutorial on the django
>>> official document.
>>>
>>>
>>> On Sat, May 12, 2012 at 2:44 PM, Karl Sutt <k...@sutt.ee> wrote:
>>>
>>>> Could you provide some code (paste it to dpaste.org for example)?
>>>> Specifically, it would be useful to see your model definition and signal
>>>> connectors etc.
>>>>
>>>> Karl Sutt
>>>>
>>>>
>>>>
>>>> On Sat, May 12, 2012 at 11:38 AM, Alireza Savand <
>>>> alireza.sav...@gmail.com> wrote:
>>>>
>>>>> Thanks for your answer Karl
>>>>> Actually yes, i want to do some versioning on model instance, but the
>>>>> problem is that the state of the model instance in pre_save is same as at
>>>>> the post_save.
>>>>>
>>>>> On Sat, May 12, 2012 at 2:32 PM, Karl Sutt <k...@sutt.ee> wrote:
>>>>>
>>>>>> Regarding pre_save signal, it is useful for doing something with the
>>>>>> "old" instance. Consider a use case where you might want to "archive" all
>>>>>> changes to, say, the user's profile. Every time a user makes a change to
>>>>>> their profile, you want to save the current state of the profile to 
>>>>>> another
>>>>>> table, or another database, and then save the new model (which overwrites
>>>>>> the current state and becomes the new current state). This sort of
>>>>>> mechanism is useful for versioning your model instances. The pre_save
>>>>>> signal allows you to create a hook that does precisely that. That is just
>>>>>> one of the use cases, but I'm sure you can think of others.
>>>>>>
>>>>>> Karl Sutt
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Sat, May 12, 2012 at 10:46 AM, Alireza Savand <
>>>>>> alireza.sav...@gmail.com> wrote:
>>>>>>
>>>>>>> Hi
>>>>>>>
>>>>>>> What is the different between pre_save signal and post_save singal.
>>>>>>> I know post_save will emited after model instance saved, and
>>>>>>> pre_save is before the saving the instance[?]
>>>>>>> but what it the point of pre_save when we cannot access the object
>>>>>>> data before the data changes.
>>>>>>> I mean user try to change the model content, like body of a post in
>>>>>>> a blog. using pre_save signal would be reasonable if i can access the
>>>>>>> post's body before the changes or in other word before the actual save()
>>>>>>> happens.
>>>>>>> If i can't access to data before save() happends, So what is the
>>>>>>> point of pre_save ?
>>>>>>>
>>>>>>> --
>>>>>>> You received this message because you are subscribed to the Google
>>>>>>> Groups "Django users" group.
>>>>>>> To view this discussion on the web visit
>>>>>>> https://groups.google.com/d/msg/django-users/-/NLEgGtpvQ4cJ.
>>>>>>> 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.
>>>>>>>
>>>>>>
>>>>>>  --
>>>>>> 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.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> + <https://github.com/Alir3z4/>+<https://sourceforge.net/users/alir3z4>
>>>>> + 
>>>>> <https://sourceforge.net/projects/yodownet/>+<https://www.transifex.net/accounts/profile/Alir3z4/>
>>>>> + <https://gist.github.com/Alir3z4>+ 
>>>>> <http://pastebin.com/u/Alir3z4>+<https://www.ohloh.net/accounts/Alir3z4>
>>>>>
>>>>>  --
>>>>> 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.
>>>>>
>>>>
>>>>  --
>>>> 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.
>>>>
>>>
>>>
>>>
>>> --
>>> + <https://github.com/Alir3z4/>+ <https://sourceforge.net/users/alir3z4>
>>> + 
>>> <https://sourceforge.net/projects/yodownet/>+<https://www.transifex.net/accounts/profile/Alir3z4/>
>>> + <https://gist.github.com/Alir3z4>+ 
>>> <http://pastebin.com/u/Alir3z4>+<https://www.ohloh.net/accounts/Alir3z4>
>>>
>>>  --
>>> 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.
>>>
>>
>>  --
>> 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.
>>
>
>
>
> --
> + <https://github.com/Alir3z4/>+ 
> <https://sourceforge.net/users/alir3z4>+<https://sourceforge.net/projects/yodownet/>
> + 
> <https://www.transifex.net/accounts/profile/Alir3z4/>+<https://gist.github.com/Alir3z4>
> + <http://pastebin.com/u/Alir3z4>+<https://www.ohloh.net/accounts/Alir3z4>
>
>  --
> 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.
>

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