Stopping request when exception occurs (admin interface)

28 views
Skip to first unread message

ia...@me.com

unread,
Nov 26, 2014, 11:41:26 AM11/26/14
to django...@googlegroups.com
Hi there,

Hopefully an easy question. I've overridden save_model() in my admin page, and I'm wrapping my obj.save() call in a try/catch so that I can catch a RecordModifiedError. 

    def save_model(self, request, obj, form, change):
             
        from concurrency.exceptions import RecordModifiedError
        from django.http import HttpResponse
        try: 
                
            obj.save()
            #other stuff

        except RecordModifiedError:
            self.message_user(request,
                            "[!] Record modified. Please try again.",
                            level="error")
            return None

The message saying record modified is shown when it should be. However, there is also a message at the top saying that the save was successful, when in fact it was not. 
What's the proper way to stop the success message from occurring? Can I clear it, or stop the request? Return None doesn't seem to help.

Thanks!

Collin Anderson

unread,
Nov 26, 2014, 3:43:19 PM11/26/14
to django...@googlegroups.com
Hi,

Peaking at the code... 

It looks like it would also log a successful change in the history.  Is it possible to detect the change during the validation?

Looks like you could override response_change() or message_user(), or let the exception bubble up to changelist_view() and override that whole thing.

Collin
Reply all
Reply to author
Forward
0 new messages