Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>another way is to use this snippet <a href="http://djangosnippets.org/snippets/2531/" rel="nofollow">http://djangosnippets.org/snippets/2531/</a></p> <pre><code>Class Modeladmin_perso(admin.ModelAdmin): def add_view(self, request, *args, **kwargs): result = super(Modeladmin_perso, self).add_view(request, *args, **kwargs ) # Look at the referer for a query string '^.*\?.*$' ref = request.META.get('HTTP_REFERER', '') if ref.find('?') != -1: # We've got a query string, set the session value request.session['filtered'] = ref if request.POST.has_key('_save'): """ We only kick into action if we've saved and if there is a session key of 'filtered', then we delete the key. """ try: if request.session['filtered'] is not None: result['Location'] = request.session['filtered'] request.session['filtered'] = None except: pass return result """ Used to redirect users back to their filtered list of locations if there were any """ def change_view(self, request, object_id, extra_context={}): """ save the referer of the page to return to the filtered change_list after saving the page """ result = super(Modeladmin_perso, self).change_view(request, object_id, extra_context ) # Look at the referer for a query string '^.*\?.*$' ref = request.META.get('HTTP_REFERER', '') if ref.find('?') != -1: # We've got a query string, set the session value request.session['filtered'] = ref if request.POST.has_key('_save'): """ We only kick into action if we've saved and if there is a session key of 'filtered', then we delete the key. """ try: if request.session['filtered'] is not None: result['Location'] = request.session['filtered'] request.session['filtered'] = None except: pass return result </code></pre> <p>the good thing is you don't have to hack anything.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload