diff --git a/bookshelf_management/apps/mgmt/__pycache__/views.cpython-36.pyc b/bookshelf_management/apps/mgmt/__pycache__/views.cpython-36.pyc index ed17dd4..5054d20 100644 Binary files a/bookshelf_management/apps/mgmt/__pycache__/views.cpython-36.pyc and b/bookshelf_management/apps/mgmt/__pycache__/views.cpython-36.pyc differ diff --git a/bookshelf_management/apps/mgmt/templates/bookshelves.html b/bookshelf_management/apps/mgmt/templates/bookshelves.html deleted file mode 100644 index 4ee553f..0000000 --- a/bookshelf_management/apps/mgmt/templates/bookshelves.html +++ /dev/null @@ -1,2 +0,0 @@ -{% extends "mgmt/base_site.html" %} -{% block title %}Test page{% endblock %} \ No newline at end of file diff --git a/bookshelf_management/apps/mgmt/templates/generic_template.html b/bookshelf_management/apps/mgmt/templates/generic_template.html new file mode 100644 index 0000000..6dac368 --- /dev/null +++ b/bookshelf_management/apps/mgmt/templates/generic_template.html @@ -0,0 +1,21 @@ + + + + {% block title %}Local Library{% endblock %} + + + + + {% load static %} + + + +
+
+
+
+
{% block content %}{% endblock %}
+
+
+ + \ No newline at end of file diff --git a/bookshelf_management/apps/mgmt/templates/index.html b/bookshelf_management/apps/mgmt/templates/index.html new file mode 100644 index 0000000..e39da03 --- /dev/null +++ b/bookshelf_management/apps/mgmt/templates/index.html @@ -0,0 +1,23 @@ +{% extends "generic_template.html" %} + +{% block content %} +

{{bookshelf}}

+

Bookshelf

+ + Number of Books in Bookshelf:

{{ total }}

+ +

Book List

+ {% if books %} + + {% else %} +

There are no books in the bookshelf.

+ {% endif %} + {% endblock %} + + diff --git a/bookshelf_management/apps/mgmt/views.py b/bookshelf_management/apps/mgmt/views.py index d9eb973..6bca48e 100644 --- a/bookshelf_management/apps/mgmt/views.py +++ b/bookshelf_management/apps/mgmt/views.py @@ -1,8 +1,27 @@ from .models import Book, Bookshelf, BookshelfToBook from django.http import HttpResponse +from django.shortcuts import render + + +from django.views import generic + +# class BookListView(generic.ListView): +# model = Book + + + def booksInBookshelf(request, bookshelfId): + bookshelfName = Bookshelf.objects.get(id=bookshelfId).bookshelf idList = BookshelfToBook.objects.filter(fk_bookshelves=bookshelfId).values_list('fk_books', flat=True) books = Book.objects.filter(id__in=idList) - return HttpResponse(books) + + context = { + 'books': books, + 'total': len(books), + 'bookshelf': bookshelfName, + } + + + return render(request, 'index.html', context=context)