Display user message from alarm in admin

I have a pre-save listener that updates the second model. Same as in this example:

  • Django Signals to update another model

I want to inform the user that the listener was able to update the model and provide some information. Normally, I think I could use the built-in message functions that django has. The problem is that the signal does not have access to the "request". Therefore, I do not see how to use the built-in in the Django Messaging Framework.

Is there a known way to send a message to a user in the admin? Maybe overriding the save () method for one of the models? (the one who sends the signal or receives), but I don’t think the save () method has access to the "request"?

Should it be something that others want to do too?

+4
django
source share
1 answer

You can override the save_model method in ModelAdmin. Something like that:

from django.contrib import messages # your imports ... # your code def save_model(self, request, obj, form, change): obj.user = request.user obj.save() # you can just call super(YourModelAdminName, self).save_model(request, obj, form, change) messages.add_message(request, messages.INFO, 'Text of message') 
+5
source share

All Articles