|
6 | 6 | admin.site.register(Status, OwnerAdmin)
|
7 | 7 |
|
8 | 8 |
|
| 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 | + |
9 | 29 | @admin.register(Journal)
|
10 | 30 | class JournalAdmin(OwnerAdmin):
|
11 | 31 | list_display = ['local_name', 'original_name', 'status', 'last_watched_season', 'last_watched_series',
|
12 | 32 | 'last_watched_date', 'rating', 'comment', 'owner']
|
13 |
| - list_filter = ['status', 'rating'] |
| 33 | + list_filter = [StatusListFilter, 'rating'] |
14 | 34 | search_fields = ['local_name', 'original_name', 'comment']
|
15 | 35 |
|
0 commit comments