I have a pre-save signal listener that updates a second model. The same as this example:
I'd like to let the user know that the listener succeeded in updating the model and provide some information. Normally, I would think I could use the built in messages functionality that django has. The problem is that the signal doesn't have access to 'request'. So I can't see how to use the built in Django Messages Framework.
Is there a known method for sending a message to the user in the admin? Maybe by overriding the save() method for one of the models? (the one sending the signal, or receiving), but I don't think the save() method has access to 'request' either?
This must be something others want to do as well?
You can override save_model method in ModelAdmin. Something like this:
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With