I've overridden my save_model() function to wrap the obj.save() call in a try/catch.
def save_model(self, request, obj, form, change):
from concurrency.exceptions import RecordModifiedError
from django.http import HttpResponse
try:
obj.save()
# some other stuff
except RecordModifiedError:
messages.error(request, "[!] Record modified. Please try again.")
#self.message_user(request, "[!] Record modified. Please try again.", level="error")
Catching the RecordModifiedError is working, and the data is not saved. However, the confirmation message that appears on a successful save is still showing, as is the error. I have two contradictory messages being shown!
I'm wondering how to prevent the success message from being displayed. Thanks!
EDIT: also tried the self.message_user()
function, but it didn't block the success message either.
doesnot it have to be in this way?