Is it possible to get a signed in django user (that calls model’s delete method) in a callback connected to pre_delete signal?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
pre_deletesignal doesn’t pass the request instance, but you can add a decorator, that adds it, and to use that decorator on a view, which deletes the specified Model.Assuming that this is the callback function:
which is being added in the decorator:
And use the decorator on the view in the way you call it – instead of
pre_delete.connect(pre_delete_cb, MyModel), use:and then in the callback you’ll have access to the request as:
You can add this on global level, not just per view – using a Middleware: