From e3396acbd06ca446af04b73b5c1b78cbe56423a9 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 10 May 2018 12:56:45 +0300 Subject: [PATCH] Update profile school qs --- apps/user/views.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/user/views.py b/apps/user/views.py index 4a082294..a771152e 100644 --- a/apps/user/views.py +++ b/apps/user/views.py @@ -17,6 +17,7 @@ from django.contrib.auth import get_user_model from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.hashers import check_password, make_password from django.http import Http404 +from django.db.models import F, Func from django.urls import reverse_lazy from django.utils.decorators import method_decorator from django.utils.timezone import now @@ -72,12 +73,15 @@ class UserView(DetailView): Pingback.PINGBACK_TYPE_GOODWILL, Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, ], - ).last() + ) + school_schedules_purchased = school_payment.annotate( + joined_weekdays=Func(F('weekdays'), function='unnest',) + ).values_list('joined_weekdays', flat=True).distinct() context['school_payment'] = school_payment - if school_payment and school_payment.date_end: - context['school_days_left'] = (school_payment.date_end - now().date()).days + if school_payment.exists() and school_payment.last().date_end: + context['school_days_left'] = (school_payment.last().date_end - now().date()).days context['school_schedules'] = SchoolSchedule.objects.filter( - weekday__in=school_payment.weekdays if school_payment else [], + weekday__in=school_schedules_purchased if school_payment.exists() else [], ) return context