Skip to content

Commit e49cbad

Browse files
committed
add: Custom StatusListFilter
1 parent afaf028 commit e49cbad

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

tv_series/admin.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,30 @@
66
admin.site.register(Status, OwnerAdmin)
77

88

9+
class StatusListFilter(admin.SimpleListFilter):
10+
title = 'status list filter'
11+
parameter_name = 'status'
12+
13+
def lookups(self, request, model_admin):
14+
def statuses_to_tuple(statuses):
15+
return [(status.pk, status.name) for status in statuses]
16+
17+
current_user = request.user
18+
19+
if current_user.is_superuser:
20+
return statuses_to_tuple(Status.objects.all())
21+
22+
return statuses_to_tuple(Status.objects.filter(owner=current_user))
23+
24+
def queryset(self, request, queryset):
25+
if self.value() is not None:
26+
return queryset.filter(status__pk=self.value())
27+
28+
929
@admin.register(Journal)
1030
class JournalAdmin(OwnerAdmin):
1131
list_display = ['local_name', 'original_name', 'status', 'last_watched_season', 'last_watched_series',
1232
'last_watched_date', 'rating', 'comment', 'owner']
13-
list_filter = ['status', 'rating']
33+
list_filter = [StatusListFilter, 'rating']
1434
search_fields = ['local_name', 'original_name', 'comment']
1535

0 commit comments

Comments
 (0)