From: Guillaume Pellerin Date: Mon, 11 May 2015 21:54:04 +0000 (+0200) Subject: add period filter to student admin list X-Git-Tag: 1.1~258 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=7aee9e3ee6a1bdb32d455f503be597fc03519fbc;p=teleforma.git add period filter to student admin list --- diff --git a/teleforma/admin.py b/teleforma/admin.py index d60a7991..4847e737 100644 --- a/teleforma/admin.py +++ b/teleforma/admin.py @@ -4,6 +4,34 @@ from teleforma.exam.models import * from django.contrib import admin from django.contrib.auth.models import User from django.contrib.auth.admin import UserAdmin +from django.contrib.admin import SimpleListFilter +from django.utils.translation import ugettext_lazy as _ + + +class PeriodListFilter(SimpleListFilter): + + title = _('period') + + # Parameter for the filter that will be used in the URL query. + parameter_name = 'period' + + 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 ( (period.name, period.name) for period in Period.objects.all() ) + + def queryset(self, request, queryset): + """ + Returns the filtered queryset based on the value + provided in the query string and retrievable via + `self.value()`. + """ + return queryset.filter(trainings__period__name=self.value()) class PaymentInline(admin.StackedInline): @@ -27,7 +55,7 @@ class StudentAdmin(admin.ModelAdmin): filter_horizontal = ['trainings'] inlines = [PaymentInline, OptionalFeeInline, DiscountInline] search_fields = ['user__first_name', 'user__last_name', 'user__username'] - list_filter = ['user__is_active', 'is_subscribed', 'trainings', 'iej', + list_filter = [PeriodListFilter, 'user__is_active', 'is_subscribed', 'trainings', 'iej', 'procedure', 'written_speciality', 'oral_speciality', 'oral_1', 'oral_2'] list_display = ['student_name', 'total_payments', 'total_fees', 'balance']