[Fixed]-Django-admin: How to redirect to another URL after Object save?

35👍

You can override the response_add and response_change methods.

from django.shortcuts import redirect

class PaymentAdmin(VersionAdmin, admin.ModelAdmin):
    def response_add(self, request, obj, post_url_continue=None):
        return redirect('/admin/sales/invoice')

    def response_change(self, request, obj):
        return redirect('/admin/sales/invoice')

It isn’t possible to return a response from inside a signal handler. You don’t want to override change_view because that handles saving the form as well as returning the response.

Leave a comment