Adding `next` url to admin django admin link

In my django project, I am creating a link to the admin interface so that users can edit the object:

<a href="{% url admin:mode_change object.id %}">modify object</a> 

this works fine, but after the user has finished editing the object in the admin interface, I would like to automatically return the user to the original URL (or another URL). Currently, after a user changes an object, he / she enters the admin interface, looking through all the model entries.

Is there a way to provide a return url for an admin link?

+4
source share
1 answer

it works:

 admin.py: class ModelAdmin(admin.ModelAdmin): form = ModelForm def response_change(self, request, obj): res = super(ModelAdmin, self).response_change(request, obj) if "next" in request.GET: return HttpResponseRedirect(request.GET['next']) else: return res 

and in the template (where currentUrl is the variable generated in the view):

 <a href="{% url admin:mode_change object.id %}?next={{ currentUrl }}">modify object</a> 
+7
source

Source: https://habr.com/ru/post/1432461/


All Articles