From 321e667cf199ab904fa1e8d20f246ef02d70bc20 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Fri, 13 Apr 2018 16:56:50 +0300 Subject: [PATCH] Add SchoolView --- apps/school/urls.py | 6 +++++- apps/school/views.py | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/school/urls.py b/apps/school/urls.py index d14d4a5a..3db299bb 100644 --- a/apps/school/urls.py +++ b/apps/school/urls.py @@ -1,8 +1,12 @@ from django.urls import path, include -from .views import LiveLessonsView, LiveLessonEditView, LiveLessonsDetailView +from .views import ( + LiveLessonsView, LiveLessonEditView, + LiveLessonsDetailView, SchoolView, +) urlpatterns = [ + path('', SchoolView.as_view(), name='school'), path('lessons/', LiveLessonsView.as_view(), name='lessons'), path('lessons//edit', LiveLessonEditView.as_view(), name='lessons-edit'), path('lessons//', LiveLessonsDetailView.as_view(), name='lesson-detail'), diff --git a/apps/school/views.py b/apps/school/views.py index a0847af1..422eeaf6 100644 --- a/apps/school/views.py +++ b/apps/school/views.py @@ -1,10 +1,11 @@ from django.contrib.auth import get_user_model from django.contrib.auth.decorators import login_required, user_passes_test +from django.db.models import Min from django.shortcuts import get_object_or_404 from django.utils.decorators import method_decorator from django.views.generic import ListView, UpdateView, TemplateView, DetailView -from .models import LiveLesson +from .models import LiveLesson, SchoolSchedule User = get_user_model() @@ -47,3 +48,15 @@ class LiveLessonEditView(TemplateView): context['object'] = self.object context['live'] = 'true' return context + + +class SchoolView(TemplateView): + template_name = 'school/school.html' + + def get_context_data(self): + context = super().get_context_data() + context.update({ + 'school_schedules': SchoolSchedule.objects.all(), + 'min_school_price': SchoolSchedule.objects.all().aggregate(Min('month_price'))['month_price__min'], + }) + return context