Redirect with change list with filters intact with admin actions

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
def accept_selected(self, request, queryset):
    n = queryset.count()
        
    for review in queryset:
        review.accept()
        self.message_user(request, _("Successfully accepted %(count)d %(items)s.") % {
                "count": n, "items": model_ngettext(self.opts, n)
            })
        # the next line is the one you'll be interested in
        return HttpResponseRedirect(request.get_full_path())            
    accept_selected.short_description = "Accept Selected Reviews"

More like this

  1. View all log entries in the admin by jakub 2 years, 9 months ago
  2. Action that respects the filters in changeview_list by grillermo 1 year, 6 months ago
  3. Generic CSV export admin action factory with relationship spanning fields and labels by blackrobot 1 year, 3 months ago
  4. Custom management command to list recent admin actions by pbx 4 years, 9 months ago
  5. Return to a filtered changelist on change form save by richardbolt 3 years, 8 months ago

Comments

akaihola (on August 8, 2009):

The indentation for line 11 is probably wrong.

#

(Forgotten your password?)