X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/891c65c58eef499c1ffc3a5fe690e1b6bff0f0db..b0fadf2591f3af957c1c8e0307d0bcef9e9f8538:/src/club/admin.py?ds=sidebyside diff --git a/src/club/admin.py b/src/club/admin.py index 2f07a4f41..2ba842a81 100644 --- a/src/club/admin.py +++ b/src/club/admin.py @@ -1,4 +1,3 @@ - # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -81,6 +80,27 @@ class ScheduleForm(forms.ModelForm): fields = '__all__' +class SourceFilter(admin.SimpleListFilter): + title = _('Source') # display title + parameter_name = 'source' + template = "admin/long_filter.html" + + def lookups(self, request, model_admin): + lookups = [ + (m, m) for m in + model_admin.model.objects.exclude(source='').values_list('source', flat=True).distinct()[:10] + ] + print(lookups) + return lookups + + def queryset(self, request, queryset): + return queryset + + #field_name = 'source' # name of the foreign key field + + + + class ScheduleAdmin(admin.ModelAdmin): form = ScheduleForm @@ -89,8 +109,12 @@ class ScheduleAdmin(admin.ModelAdmin): 'method' ] list_display_links = ['email', 'started_at'] - search_fields = ['email'] - list_filter = ['is_cancelled', 'monthly', 'yearly', 'method', PayedFilter, ExpiredFilter, 'source'] + search_fields = ['email', 'source'] + list_filter = [ + 'is_cancelled', 'monthly', 'yearly', 'method', + PayedFilter, ExpiredFilter, + SourceFilter, + ] filter_horizontal = ['consent'] date_hierarchy = 'started_at' raw_id_fields = ['membership']