Redirect on admin Save

To change the redirect destination after save in the admin, you need to override response_add() (for adding new instances) and response_change() (for changing existing ones) in the ModelAdmin class.

See the original code in django.contrib.admin.options.

Quick examples to make it clearer how to do this (would be within a ModelAdmin class):

from django.core.urlresolvers import reverse

def response_add(self, request, obj, post_url_continue=None):
    """
    This makes the response after adding go to another 
    app's changelist for some model
    """
    return HttpResponseRedirect(
        reverse("admin:otherappname_modelname_changelist")
    )


def response_change(self, request, obj, post_url_continue=None):
    """
    This makes the response go to the newly created
    model's change page without using reverse
    """
    return HttpResponseRedirect("../%s" % obj.id)

Leave a Comment