Skip to content
Snippets Groups Projects
Commit 03500192 authored by Denis Golomazov's avatar Denis Golomazov Committed by Dmitry Shachnev
Browse files

Add ActorListFilter to filter by actor type. Add description column to display.

parent 3d8804ef
No related branches found
No related tags found
No related merge requests found
from django.contrib import admin
from django.contrib.admin import SimpleListFilter
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from actstream import models
......@@ -9,10 +13,53 @@ except ImportError:
ModelAdmin = admin.ModelAdmin
class ActorListFilter(SimpleListFilter):
# Human-readable title which will be displayed in the
# right admin sidebar just above the filter options.
title = _('actor type')
# Parameter for the filter that will be used in the URL query.
parameter_name = 'actor_type'
def lookups(self, request, model_admin):
"""
Returns a list of tuples. The first element in each
tuple is the coded value for the option that will
appear in the URL query. The second element is the
human-readable name for the option that will appear
in the right sidebar.
"""
return (
('non-staff', _('All excluding staff')),
('anonymous', _('Anonymous users')),
('registered', _('Registered users')),
('staff', _('Staff')),
)
def queryset(self, request, queryset):
"""
Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`.
"""
# Compare the requested value (either '80s' or 'other')
# to decide how to filter the queryset.
user_content_type = ContentType.objects.get_for_model(User)
staff = User.objects.filter(is_staff=True)
if self.value() == 'non-staff':
return queryset.exclude(actor_content_type=user_content_type, actor_object_id__in=staff)
if self.value() == 'anonymous':
return queryset.exclude(actor_content_type=user_content_type)
if self.value() == 'registered':
return queryset.filter(actor_content_type=user_content_type).exclude(actor_object_id__in=staff)
if self.value() == 'staff':
return queryset.filter(actor_content_type=user_content_type, actor_object_id__in=staff)
class ActionAdmin(ModelAdmin):
date_hierarchy = 'timestamp'
list_display = ('actor', 'verb', 'action_object_content_type', 'action_object', 'target_content_type', 'target', 'timestamp')
list_filter = ('verb', 'timestamp')
list_display = ('actor', 'verb', 'description', 'action_object_content_type', 'action_object', 'target_content_type', 'target', 'timestamp')
list_filter = (ActorListFilter, 'timestamp', 'verb')
raw_id_fields = ('actor_content_type', 'target_content_type',
'action_object_content_type')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment