From 83df344ca9e14eb4c1c64beb2119bb1f51461aca Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Wed, 15 Apr 2015 10:32:33 +0200 Subject: [PATCH] add admin filters --- teleforma/admin.py | 9 ++++++++- teleforma/views/core.py | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/teleforma/admin.py b/teleforma/admin.py index e7660c50..edf40a3c 100644 --- a/teleforma/admin.py +++ b/teleforma/admin.py @@ -27,7 +27,9 @@ 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'] + list_filter = ['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'] def student_name(self, instance): @@ -36,6 +38,11 @@ class StudentAdmin(admin.ModelAdmin): def balance(self, instance): return instance.total_payments - instance.total_fees + def queryset(self, request): + qs = super(StudentAdmin, self).queryset(request) + qs = qs.annotate(models.Count('warehouse__amount')) + return qs + class ProfessorProfileInline(admin.StackedInline): model = Professor filter_horizontal = ['courses'] diff --git a/teleforma/views/core.py b/teleforma/views/core.py index 786ef777..fe5afc25 100644 --- a/teleforma/views/core.py +++ b/teleforma/views/core.py @@ -436,7 +436,7 @@ class DocumentView(CourseAccessMixin, DetailView): def download(self, request, pk): courses = get_courses(request.user) - document = Document.objects.get(id=pk) + document = Document.objects.get(pk=pk) if get_access(document, courses): fsock = open(document.file.path, 'r') mimetype = mimetypes.guess_type(document.file.path)[0] @@ -450,7 +450,7 @@ class DocumentView(CourseAccessMixin, DetailView): def view(self, request, pk): courses = get_courses(request.user) - document = Document.objects.get(id=pk) + document = Document.objects.get(pk=pk) if get_access(document, courses): fsock = open(document.file.path, 'r') mimetype = mimetypes.guess_type(document.file.path)[0] -- 2.39.5