From 0a93b93a7e81ab1a21e48389bf390d3c4e01c0cc Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 2 Jun 2018 18:21:04 +0200 Subject: [PATCH] Simplify list book and supplies view --- manuels/templates/manuels/list_books_supplies.html | 4 ++-- manuels/views.py | 14 ++------------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/manuels/templates/manuels/list_books_supplies.html b/manuels/templates/manuels/list_books_supplies.html index fe9f859..7de4c65 100644 --- a/manuels/templates/manuels/list_books_supplies.html +++ b/manuels/templates/manuels/list_books_supplies.html @@ -58,7 +58,7 @@ - {% for book in books %} + {% for book in teacher.book_set.all %} {% if not teacher.has_confirmed_list %} @@ -115,7 +115,7 @@ - {% for supply in supplies %} + {% for supply in teacher.suppliesrequirement_set.all %} {% if not teacher.has_confirmed_list %} diff --git a/manuels/views.py b/manuels/views.py index eed4980..6af9e02 100644 --- a/manuels/views.py +++ b/manuels/views.py @@ -2,7 +2,7 @@ from django.contrib import messages from django.contrib.auth.mixins import PermissionRequiredMixin from django.shortcuts import get_object_or_404, redirect from django.urls import reverse -from django.views.generic import CreateView, ListView, UpdateView, DeleteView, FormView +from django.views.generic import CreateView, ListView, UpdateView, DeleteView, FormView, DetailView, TemplateView from manuels.forms import AddBookForm, AddSuppliesForm, EditBookForm, EditSuppliesForm from manuels.models import Teacher, Book, SuppliesRequirement @@ -46,18 +46,8 @@ class BaseTeacherView: return context -class ListBooksView(BaseTeacherView, ListView): - model = Book +class ListBooksView(BaseTeacherView, TemplateView): template_name = 'manuels/list_books_supplies.html' - context_object_name = 'books' - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - context['supplies'] = SuppliesRequirement.objects.filter(teacher=self.teacher) - return context - - def get_queryset(self): - return Book.objects.filter(teacher=self.teacher) class ItemView(BaseTeacherView):