Monday, August 30, 2010

Re: Pass extra data in post_save?

If you have control of the sending model, you can, so long as you
avoid field and method names, just add a reference to the user to the
instance.

inst.user = request.user

Since it's not a field, it won't affect the saving of the instance,
but it will be there in the instance passed in the signal.

Bill

On Sun, Aug 29, 2010 at 9:12 AM, bruno desthuilliers
<bruno.desthuilliers@gmail.com> wrote:
> On 27 août, 18:07, AK <akspamcatc...@gmail.com> wrote:
>> From what I can tell in the documentation, a post_save signal only
>> passes sender, instance, created, and using.  I would love to use this
>> signal to update information in the instance, such as the datetime of
>> when it was saved.
>
> Just add a datetime field with 'autonow=True', it will work OOTB.
>
>>  This would be fine, except that I want to also
>> keep track of the user who made the save (from request.user).
>
> If you want request.user, you need to have access to the request
> object. IOW, you have to do this by yourself in your views.
>
>
>>  What is
>> the best way to get this information to a post-save signal?
>
> The best way is to avoid using post_save for such things - what do you
> think will happen if you call instance.save on the instance passed to
> a post_save signal ?-)
>
>
>
> --
> 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+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment