- Author:
- AndrewIngram
- Posted:
- July 10, 2009
- Language:
- Python
- Version:
- 1.0
- Score:
- 0 (after 0 ratings)
When using the django admin as a means of moderating reviews on a site, the obvious choice was to use admin actions and do everything from a single screen. The I stumbled across was that after the actions were peformed, the app redirected to the change list without any filters. This meant that filtering on un-moderated reviews was lost as soon as a change was made.
It turns out that the solution is pretty simple, you just put a redirect to request.get_full_path() at the end of the admin action. I think this should be the default behaviour, but the fix is simple nonetheless.
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
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
The indentation for line 11 is probably wrong.
#
Please login first before commenting.