create bookshelf view
parent
b3692810b6
commit
0a815dd42d
Binary file not shown.
|
@ -1,2 +0,0 @@
|
|||
{% extends "mgmt/base_site.html" %}
|
||||
{% block title %}Test page{% endblock %}
|
|
@ -0,0 +1,21 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
{% block title %}<title>Local Library</title>{% endblock %}
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
|
||||
<!-- Add additional CSS in static file -->
|
||||
{% load static %}
|
||||
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-sm-2">
|
||||
</div>
|
||||
<div class="col-sm-10 ">{% block content %}{% endblock %}</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,23 @@
|
|||
{% extends "generic_template.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{{bookshelf}}</h1>
|
||||
<h2>Bookshelf</h2>
|
||||
|
||||
<strong>Number of Books in Bookshelf:</strong> <p>{{ total }}</p>
|
||||
|
||||
<h1>Book List</h1>
|
||||
{% if books %}
|
||||
<ul>
|
||||
{% for book in books %}
|
||||
<li>
|
||||
<a href="https://www.gutenberg.org/ebooks/{{ book.id }}">{{ book.title }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>There are no books in the bookshelf.</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue