Brainstorm's snippets (1/258)

  Redirect to an arbitrary URL After Saving in Django Admin

Put following change_view-method in your admin.py and now you can make links to admin change page that return you back to where you came from:

class BlogEntryAdmin(admin.ModelAdmin):

    ...

    def change_view(self, request, object_id, form_url='', extra_context=None):
        result = super(BlogEntryAdmin, self).change_view(request, object_id, form_url, extra_context)
        if request.GET.get('return_to', False):
            result['Location'] = request.GET['return_to']
        return result

In your template you'd have something like:

{% if request.user.is_staff %}
    <a href="/admin/blog/blogentry/{{ entry.pk }}/?return_to={{ entry.get_absolute_url }}">Edit in admin</a>
{% endif %}