Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8242635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:14:15+00:00 2026-06-07T21:14:15+00:00

Is it possible to get a signed in django user (that calls model’s delete

  • 0

Is it possible to get a signed in django user (that calls model’s delete method) in a callback connected to pre_delete signal?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:14:18+00:00Added an answer on June 7, 2026 at 9:14 pm

    The pre_delete signal 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:

    def pre_delete_cb(sender, instance, using, **kwargs):
        pass
    

    which is being added in the decorator:

    from django.db.models.signals import pre_delete
    from functools import wraps
    from django.utils.decorators import available_attrs
    
    def pre_delete_dec(cb, sender):
        def decorator(view_func):
            @wraps(view_func, assigned=available_attrs(view_func))
            def _wrapped_view(request, *args, **kwargs):
                cb.request = request  # here we add the request to the callback function
                pre_delete.connect(cb, sender=sender)  # and connecting the real pre_delete to the callback
                return view_func(request, *args, **kwargs)
            return _wrapped_view
        return decorator
    

    And use the decorator on the view in the way you call it – instead of pre_delete.connect(pre_delete_cb, MyModel), use:

    @pre_delete_dec(pre_delete_cb, MyModel)
    def myview(request):
    

    and then in the callback you’ll have access to the request as:

    def pre_delete_cb(sender, instance, using, **kwargs):
        current_user = pre_delete_cb.request.user
    

    You can add this on global level, not just per view – using a Middleware:

    from django.db.models.signals import pre_delete
    
    def pre_delete_cb(sender, instance, using, **kwargs):
        current_user = pre_delete_cb.request.user
    
    class PreDeleteMiddleware(object):
        def process_view(self, request, view_func, view_args, view_kwargs):
            pre_delete_cb.request = request
            from myapp.models import MyModel
            pre_delete.connect(pre_delete_cb, sender=MyModel)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is it possible to get the user_id from the facebook user without requiring the
does anyone know how to (if possible) get the owner of the tag on
I am trying to work out if it is possible get JPA to persist
Possible Duplicate: Get all files from VSS for a given date? I need to
Possible Duplicate: Get a list of dates between two dates This is my sql:
Possible Duplicate: Get URL of ASP.Net Page in code-behind I'm trying to hold current
Possible Duplicate: Get full path of a file with FileUpload Control I want to
Possible Duplicate: Get image data in Javascript? Convert an image into binary data in
Possible Duplicate: get name of current PHP script in include file Can an included
Is it possible to get the 'nth' return value from a function without having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.