Renamed models like how Django does it, fixed commens on book template

This commit is contained in:
MassiveAtoms 2020-07-09 01:00:51 -03:00
parent 99a74b75a9
commit 62b9dfd94f
17 changed files with 113 additions and 223 deletions

View File

@ -1,16 +1,16 @@
from django.contrib import admin from django.contrib import admin
from .models import Authors, Books, Languages, Publishers, Series, Tags from .models import Author, Book, Language, Publisher, Series, Tag
# Register your models here. # Register your models here.
@admin.register(Authors) @admin.register(Author)
class AuthorAdmin(admin.ModelAdmin): class AuthorAdmin(admin.ModelAdmin):
list_display = (["name"]) list_display = (["name"])
@admin.register(Languages) @admin.register(Language)
class LanguageAdmin(admin.ModelAdmin): class LanguageAdmin(admin.ModelAdmin):
list_display = (["id", "lang_code"]) list_display = (["id", "lang_code"])
@admin.register(Publishers) @admin.register(Publisher)
class PublisherAdmin(admin.ModelAdmin): class PublisherAdmin(admin.ModelAdmin):
list_display = (["id","name"]) list_display = (["id","name"])
@ -18,10 +18,10 @@ class PublisherAdmin(admin.ModelAdmin):
class SeriesAdmin(admin.ModelAdmin): class SeriesAdmin(admin.ModelAdmin):
list_display = (["id","name"]) list_display = (["id","name"])
@admin.register(Tags) @admin.register(Tag)
class TagAdmin(admin.ModelAdmin): class TagAdmin(admin.ModelAdmin):
list_display = (["id","name"]) list_display = (["id","name"])
@admin.register(Books) @admin.register(Book)
class BookAdmin(admin.ModelAdmin): class BookAdmin(admin.ModelAdmin):
list_display = (["id","title", "author_sort"]) list_display = (["id","title", "author_sort"])

View File

@ -1,107 +0,0 @@
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///C://Users//MassiveAtoms//Documents//Calibre Library//metadata.db.', echo=True)
Base = declarative_base(engine)
########################################################################
class Author(Base): # needed
""""""
__tablename__ = 'authors'
__table_args__ = {'autoload':True}
# has int id, text name, sort
class Comment(Base): # needed
""""""
__tablename__ = 'comments'
__table_args__ = {'autoload':True}
# has int id, int book, text text
# class Data(Base): # maybe
# """"""
# __tablename__ = 'data'
# __table_args__ = {'autoload':True}
# # has int id, int book, text format, text name
class Identifier(Base): # needed
""""""
__tablename__ = 'identifiers'
__table_args__ = {'autoload':True}
# has int id, int book, text value
class Publisher(Base): # needed
""""""
__tablename__ = 'publishers'
__table_args__ = {'autoload':True}
# has int id, text name
class Rating(Base): # needed
""""""
__tablename__ = 'ratings'
__table_args__ = {'autoload':True}
# has int id, int rating
class Series(Base): # needed
""""""
__tablename__ = 'series'
__table_args__ = {'autoload':True}
# has int id, text name
class Tag(Base): # needed
""""""
__tablename__ = 'tags'
__table_args__ = {'autoload':True}
# has int id, text name
class Book(Base): # needed
""""""
__tablename__ = 'books'
__table_args__ = {'autoload':True}
# has int id, text title, text sort, time timestamp, time pubdate,
# float series_index, text path
class Book_author_link(Base): # needed
""""""
__tablename__ = 'books_authors_link'
__table_args__ = {'autoload':True}
# has int id, id book, id author
class Book_publisher_link(Base): # needed
""""""
__tablename__ = 'books_publishers_link'
__table_args__ = {'autoload':True}
# has int id, id book, id publisher
class Book_rating_link(Base): # needed
""""""
__tablename__ = 'books_ratings_link'
__table_args__ = {'autoload':True}
# has int id, id book, id rating
class Book_series_link(Base): # needed
""""""
__tablename__ = 'books_series_link'
__table_args__ = {'autoload':True}
# has int id, id book, id series
class Book_tags_link(Base): # needed
""""""
__tablename__ = 'books_tags_link'
__table_args__ = {'autoload':True}
# has int id, id book, id tag
#----------------------------------------------------------------------
def loadSession():
""""""
metadata = Base.metadata
Session = sessionmaker(bind=engine)
session = Session()
return session
if __name__ == "__main__":
session = loadSession()
res = session.query(Book).all()
for i in res:
print(i.id, i.title, i.sort, i.timestamp, i.pubdate, i.series_index, i.path)

View File

@ -1,12 +1,12 @@
from .models import Authors, Tags, Publishers, Languages, Ratings, Series from .models import Author, Tag, Publisher, Language, Rating, Series
def filters(request): def filters(request):
unique_authors = Authors.objects.all().order_by('sort') unique_authors = Author.objects.all().order_by('sort')
unique_tags = Tags.objects.all().order_by('name') unique_tags = Tag.objects.all().order_by('name')
unique_publishers = Publishers.objects.all().order_by('name') unique_publishers = Publisher.objects.all().order_by('name')
unique_languages = Languages.objects.all() unique_languages = Language.objects.all()
unique_ratings = Ratings.objects.all().order_by('rating') unique_ratings = Rating.objects.all().order_by('rating')
unique_series = Series.objects.all().order_by('sort') unique_series = Series.objects.all().order_by('sort')
return { return {

View File

@ -9,7 +9,7 @@ from django.db import models
from django.urls import reverse from django.urls import reverse
class Authors(models.Model): class Author(models.Model):
name = models.TextField() name = models.TextField()
sort = models.TextField(blank=True, null=True) sort = models.TextField(blank=True, null=True)
link = models.TextField() link = models.TextField()
@ -28,8 +28,8 @@ class Authors(models.Model):
class Comments(models.Model): class Comment(models.Model):
book = models.ForeignKey("Books", db_column="book", on_delete=models.CASCADE) book = models.ForeignKey("Book", db_column="book", on_delete=models.CASCADE)
text = models.TextField() text = models.TextField()
@ -57,7 +57,7 @@ class Data(models.Model):
] ]
class Identifiers(models.Model): class Identifier(models.Model):
book = models.IntegerField() book = models.IntegerField()
type = models.TextField() type = models.TextField()
val = models.TextField() val = models.TextField()
@ -71,7 +71,7 @@ class Identifiers(models.Model):
db_table = 'identifiers' db_table = 'identifiers'
class Languages(models.Model): class Language(models.Model):
lang_code = models.TextField() lang_code = models.TextField()
def get_absolute_url(self): def get_absolute_url(self):
@ -90,12 +90,12 @@ class Languages(models.Model):
] ]
class Publishers(models.Model): class Publisher(models.Model):
name = models.TextField() name = models.TextField()
sort = models.TextField(blank=True, null=True) sort = models.TextField(blank=True, null=True)
released = models.ManyToManyField( released = models.ManyToManyField(
"Books", "Book",
through='BooksPublishersLink', through='BookPublisherLink',
through_fields=('publisher', 'book'), through_fields=('publisher', 'book'),
related_name="released" related_name="released"
) )
@ -116,7 +116,7 @@ class Publishers(models.Model):
] ]
class Ratings(models.Model): class Rating(models.Model):
rating = models.IntegerField(blank=True, null=True) rating = models.IntegerField(blank=True, null=True)
def get_absolute_url(self): def get_absolute_url(self):
"""Returns the url to access a particular instance of MyModelName.""" """Returns the url to access a particular instance of MyModelName."""
@ -151,7 +151,7 @@ class Series(models.Model):
] ]
class Tags(models.Model): class Tag(models.Model):
name = models.TextField() name = models.TextField()
def get_absolute_url(self): def get_absolute_url(self):
"""Returns the url to access a particular instance of MyModelName.""" """Returns the url to access a particular instance of MyModelName."""
@ -169,7 +169,7 @@ class Tags(models.Model):
] ]
class Books(models.Model): class Book(models.Model):
title = models.TextField() title = models.TextField()
sort = models.TextField(blank=True, null=True) sort = models.TextField(blank=True, null=True)
# This field type is a guess. # This field type is a guess.
@ -186,28 +186,28 @@ class Books(models.Model):
has_cover = models.BooleanField(blank=True, null=True) has_cover = models.BooleanField(blank=True, null=True)
last_modified = models.TextField() # This field type is a guess. last_modified = models.TextField() # This field type is a guess.
authors = models.ManyToManyField( authors = models.ManyToManyField(
Authors, Author,
through='BooksAuthorsLink', through='BookAuthorLink',
through_fields=('book', 'author')) through_fields=('book', 'author'))
languages = models.ManyToManyField( languages = models.ManyToManyField(
Languages, Language,
through='BooksLanguagesLink', through='BookLanguageLink',
through_fields=('book', 'lang_code')) through_fields=('book', 'lang_code'))
publishers = models.ManyToManyField( publishers = models.ManyToManyField(
Publishers, Publisher,
through='BooksPublishersLink', through='BookPublisherLink',
through_fields=('book', 'publisher')) through_fields=('book', 'publisher'))
series = models.ManyToManyField( series = models.ManyToManyField(
Series, Series,
through='BooksSeriesLink', through='BookSeriesLink',
through_fields=('book', 'series')) through_fields=('book', 'series'))
tags = models.ManyToManyField( tags = models.ManyToManyField(
Tags, Tag,
through='BooksTagsLink', through='BookTagLink',
through_fields=('book', 'tag')) through_fields=('book', 'tag'))
ratings = models.ManyToManyField( ratings = models.ManyToManyField(
Ratings, Rating,
through='BooksRatingsLink', through='BookRatingLink',
through_fields=('book', 'rating')) through_fields=('book', 'rating'))
def get_absolute_url(self): def get_absolute_url(self):
"""Returns the url to access a particular instance of MyModelName.""" """Returns the url to access a particular instance of MyModelName."""
@ -226,10 +226,10 @@ class Books(models.Model):
] ]
class BooksAuthorsLink(models.Model): class BookAuthorLink(models.Model):
book = models.ForeignKey(Books, db_column="book", on_delete=models.CASCADE) book = models.ForeignKey(Book, db_column="book", on_delete=models.CASCADE)
author = models.ForeignKey( author = models.ForeignKey(
Authors, db_column="author", on_delete=models.CASCADE) Author, db_column="author", on_delete=models.CASCADE)
class Meta: class Meta:
managed = False managed = False
@ -240,10 +240,10 @@ class BooksAuthorsLink(models.Model):
] ]
class BooksLanguagesLink(models.Model): class BookLanguageLink(models.Model):
book = models.ForeignKey(Books, db_column="book", on_delete=models.CASCADE) book = models.ForeignKey(Book, db_column="book", on_delete=models.CASCADE)
lang_code = models.ForeignKey( lang_code = models.ForeignKey(
Languages, db_column="lang_code", on_delete=models.CASCADE) Language, db_column="lang_code", on_delete=models.CASCADE)
item_order = models.IntegerField() item_order = models.IntegerField()
class Meta: class Meta:
@ -256,10 +256,10 @@ class BooksLanguagesLink(models.Model):
] ]
class BooksPublishersLink(models.Model): class BookPublisherLink(models.Model):
book = models.ForeignKey(Books, db_column="book", on_delete=models.CASCADE) book = models.ForeignKey(Book, db_column="book", on_delete=models.CASCADE)
publisher = models.ForeignKey( publisher = models.ForeignKey(
Publishers, db_column="publisher", on_delete=models.CASCADE) Publisher, db_column="publisher", on_delete=models.CASCADE)
class Meta: class Meta:
managed = False managed = False
@ -271,18 +271,18 @@ class BooksPublishersLink(models.Model):
] ]
class BooksRatingsLink(models.Model): # TODO add this somehow class BookRatingLink(models.Model): # TODO add this somehow
book = models.ForeignKey(Books, db_column="book", on_delete=models.CASCADE) book = models.ForeignKey(Book, db_column="book", on_delete=models.CASCADE)
rating = models.ForeignKey( rating = models.ForeignKey(
Ratings, db_column="rating", on_delete=models.CASCADE) Rating, db_column="rating", on_delete=models.CASCADE)
class Meta: class Meta:
managed = False managed = False
db_table = 'books_ratings_link' db_table = 'books_ratings_link'
class BooksSeriesLink(models.Model): class BookSeriesLink(models.Model):
book = models.ForeignKey(Books, db_column="book", on_delete=models.CASCADE) book = models.ForeignKey(Book, db_column="book", on_delete=models.CASCADE)
series = models.ForeignKey( series = models.ForeignKey(
Series, db_column="series", on_delete=models.CASCADE) Series, db_column="series", on_delete=models.CASCADE)
@ -295,9 +295,9 @@ class BooksSeriesLink(models.Model):
] ]
class BooksTagsLink(models.Model): class BookTagLink(models.Model):
book = models.ForeignKey(Books, db_column="book", on_delete=models.CASCADE) book = models.ForeignKey(Book, db_column="book", on_delete=models.CASCADE)
tag = models.ForeignKey(Tags, db_column="tag", on_delete=models.CASCADE) tag = models.ForeignKey(Tag, db_column="tag", on_delete=models.CASCADE)
class Meta: class Meta:
managed = False managed = False
@ -308,7 +308,7 @@ class BooksTagsLink(models.Model):
] ]
# class BooksPluginData(models.Model): # class BookPluginData(models.Model):
# book = models.IntegerField() # book = models.IntegerField()
# name = models.TextField() # name = models.TextField()
# val = models.TextField() # val = models.TextField()

View File

@ -2,7 +2,7 @@
{% block content %} {% block content %}
{% load static %} {% load static %}
<h1>{{authors}}</h1> <h1>{{author}}</h1>
<table id="books"> <table id="books">
<tr> <tr>

View File

@ -3,15 +3,15 @@
{% block content %} {% block content %}
{% load static %} {% load static %}
<h1>Author List</h1> <h1>Author List</h1>
{% if authors_list %} {% if author_list %}
<ul> <ul>
{% for author in authors_list %} {% for author in author_list %}
<li> <li>
<a href="{{ author.get_absolute_url }}">{{ author.name }}</a> <a href="{{ author.get_absolute_url }}">{{ author.name }}</a>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
{% else %} {% else %}
<p>There are no authors in the library.</p> <p>There are no author in the library.</p>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@ -2,19 +2,19 @@
{% block content %} {% block content %}
{% load static %} {% load static %}
<h1>{{books.title}} by <h1>{{book.title}} by
{% if books.authors %} {% if book.authors %}
{% for author in books.authors.all %} {% for author in book.authors.all %}
<a href="{{author.get_absolute_url}}">{{author.name}}</a> <a href="{{author.get_absolute_url}}">{{author.name}}</a>
{%endfor%} {%endfor%}
{% else %} {% else %}
{{books.author_sort}} {{book.author_sort}}
{%endif%} {%endif%}
Published by Published by
{% if books.publishers %} {% if book.publishers %}
{% for pub in books.publishers.all %} {% for pub in book.publishers.all %}
<a href="{{pub.get_absolute_url}}">{{pub.name}}</a> <a href="{{pub.get_absolute_url}}">{{pub.name}}</a>
{%endfor%} {%endfor%}
{% else %} {% else %}
@ -23,16 +23,16 @@
{%endif%} {%endif%}
Tags: Tags:
{% if books.tags %} {% if book.tags %}
{% for tag in books.tags.all %} {% for tag in book.tags.all %}
<a href="{{tag.get_absolute_url}}">{{tag.name}}</a>, <a href="{{tag.get_absolute_url}}">{{tag.name}}</a>,
{%endfor%} {%endfor%}
{% else %} {% else %}
{%endif%} {%endif%}
Rating: Rating:
{% if books.ratings %} {% if book.ratings %}
{% for rating in books.ratings.all %} {% for rating in book.ratings.all %}
<a href="{{rating.get_absolute_url}}">{{rating}}</a> <a href="{{rating.get_absolute_url}}">{{rating}}</a>
{%endfor%} {%endfor%}
{% else %} {% else %}
@ -40,8 +40,11 @@
<a href="{{book.publisher.get_absolute_url}}">{{book.publisher}}</a> <a href="{{book.publisher.get_absolute_url}}">{{book.publisher}}</a>
</h1> </h1>
{{comment}}
<a href="{% static "" %}{{download}}"><img src="{% static "" %}{{imgpath}}" alt="" srcset=""></a>
<a href="{% static "" %}{{download}}"><img src="{% static "" %}{{imgpath}}" alt="download" srcset=""></a>
{% autoescape off %}
{{comment}}
{% endautoescape %}
{% endblock %} {% endblock %}

View File

@ -13,7 +13,7 @@
<th onclick="sortTable(3)">Tags</th> <th onclick="sortTable(3)">Tags</th>
<th onclick="sortTable(4)">Added</th> <th onclick="sortTable(4)">Added</th>
</tr> </tr>
{% for book in books_list %} {% for book in book_list %}
<tr> <tr>
<td><a href="{{ book.get_absolute_url }}">{{ book.title }}</a></td> <td><a href="{{ book.get_absolute_url }}">{{ book.title }}</a></td>
<td>{{book.author_sort}}</td> <td>{{book.author_sort}}</td>

View File

@ -2,9 +2,9 @@
{% block content %} {% block content %}
{% load static %} {% load static %}
<h1>{{publishers}} </h1> <h1>{{publisher}} </h1>
{% if publishers.released %} {% if publisher.released %}
<table id="books"> <table id="books">
<tr> <tr>
<!--When a header is clicked, run the sortTable function, with a parameter, 0 for sorting by names, 1 for sorting by country:--> <!--When a header is clicked, run the sortTable function, with a parameter, 0 for sorting by names, 1 for sorting by country:-->
@ -14,7 +14,7 @@
<th onclick="sortTable(3)">Tags</th> <th onclick="sortTable(3)">Tags</th>
<th onclick="sortTable(4)">Added</th> <th onclick="sortTable(4)">Added</th>
</tr> </tr>
{% for book in publishers.released.all %} {% for book in publisher.released.all %}
<tr> <tr>
<td><a href="{{ book.get_absolute_url }}">{{ book.title }}</a></td> <td><a href="{{ book.get_absolute_url }}">{{ book.title }}</a></td>
<td>{{book.author_sort}}</td> <td>{{book.author_sort}}</td>

View File

@ -3,15 +3,15 @@
{% block content %} {% block content %}
{% load static %} {% load static %}
<h1>Publishers List</h1> <h1>Publishers List</h1>
{% if publishers_list %} {% if publisher_list %}
<ul> <ul>
{% for publisher in publishers_list %} {% for publisher in publisher_list %}
<li> <li>
<a href="{{ publisher.get_absolute_url }}">{{ publisher.name }}</a> <a href="{{ publisher.get_absolute_url }}">{{ publisher.name }}</a>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
{% else %} {% else %}
<p>There are no publishers in the library.</p> <p>There are no publisher in the library.</p>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@ -3,7 +3,7 @@
{% block content %} {% block content %}
{% load static %} {% load static %}
<h1>{{ratings}}</h1> <h1>{{rating}}</h1>
{% if books %} {% if books %}
<table id="books"> <table id="books">
<tr> <tr>
@ -18,7 +18,7 @@
<tr> <tr>
<td><a href="{{ book.get_absolute_url }}">{{ book.title }}</a></td> <td><a href="{{ book.get_absolute_url }}">{{ book.title }}</a></td>
<td>{{book.author_sort}}</td> <td>{{book.author_sort}}</td>
<td> {% for rating in book.ratings.all %} <td> {% for rating in book.rating.all %}
{{rating}} {{rating}}
{% endfor %} {% endfor %}
</td> </td>

View File

@ -3,15 +3,15 @@
{% block content %} {% block content %}
{% load static %} {% load static %}
<h1>Ratings List</h1> <h1>Ratings List</h1>
{% if ratings_list %} {% if rating_list %}
<ul> <ul>
{% for rating in ratings_list %} {% for rating in rating_list %}
<li> <li>
<a href="{{ rating.get_absolute_url }}">{{ rating.rating }}</a> <a href="{{ rating.get_absolute_url }}">{{ rating.rating }}</a>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
{% else %} {% else %}
<p>There are no ratings in the library.</p> <p>There are no rating in the library.</p>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@ -3,7 +3,7 @@
{% block content %} {% block content %}
{% load static %} {% load static %}
<h1>{{tags}}</h1> <h1>{{tag}}</h1>
{% if books %} {% if books %}
<table id="books"> <table id="books">
<tr> <tr>
@ -23,7 +23,7 @@
{% endfor %} {% endfor %}
</td> </td>
<td> <td>
{% for tag in book.tags.all %} {% for tag in book.tag.all %}
{{tag}}, {{tag}},
{% endfor %} {% endfor %}
</td> </td>

View File

@ -3,15 +3,15 @@
{% block content %} {% block content %}
{% load static %} {% load static %}
<h1>Tags List</h1> <h1>Tags List</h1>
{% if tags_list %} {% if tag_list %}
<ul> <ul>
{% for tag in tags_list %} {% for tag in tag_list %}
<li> <li>
<a href="{{ tag.get_absolute_url }}">{{ tag.name }}</a> <a href="{{ tag.get_absolute_url }}">{{ tag.name }}</a>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
{% else %} {% else %}
<p>There are no tags in the library.</p> <p>There are no tag in the library.</p>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@ -1 +0,0 @@
from . import custom

View File

@ -1,9 +0,0 @@
from django import template
from ..models import Books
register = template.Library
print("I ACTUALLY CAME HEReEe")
@register.simple_tag
def dummy():
return Books.objects.count()

View File

@ -1,68 +1,72 @@
from django.shortcuts import render from django.shortcuts import render
from django.views import generic from django.views import generic
from .models import Authors, Books, Comments, Ratings, BooksAuthorsLink, Publishers, Tags, BooksTagsLink, BooksRatingsLink, Data from .models import Author, Book, Comment, Rating, BookAuthorLink, Publisher, Tag, BookTagLink, BookRatingLink, Data
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from .forms import SearchForm from .forms import SearchForm
from django.db import models from django.db import models
from django.db.models import Q from django.db.models import Q
class SearchView(generic.TemplateView): class SearchView(generic.TemplateView):
template_name = 'search.html' template_name = 'search.html'
class ResultsView(generic.ListView): # no clue if this is secure.
class ResultsView(generic.ListView): # no clue if this is secure.
# according to this https://stackoverflow.com/questions/13574043/how-do-django-forms-sanitize-text-input-to-prevent-sql-injection-xss-etc # according to this https://stackoverflow.com/questions/13574043/how-do-django-forms-sanitize-text-input-to-prevent-sql-injection-xss-etc
# it is # it is
model = Books model = Book
template_name = 'results.html' template_name = 'results.html'
def get_queryset(self): # new
def get_queryset(self): # new
title = self.request.GET.get('title') title = self.request.GET.get('title')
author = self.request.GET.get('author') author = self.request.GET.get('author')
return Books.objects.filter( return Book.objects.filter(
Q(sort__icontains=title) and Q(author_sort__icontains=author) Q(sort__icontains=title) and Q(author_sort__icontains=author)
) )
class AuthorListView(generic.ListView): class AuthorListView(generic.ListView):
model = Authors model = Author
class BookListView(generic.ListView): class BookListView(generic.ListView):
model = Books model = Book
class PublisherListView(generic.ListView): class PublisherListView(generic.ListView):
model = Publishers model = Publisher
class RatingListView(generic.ListView): class RatingListView(generic.ListView):
model = Ratings model = Rating
class TagListView(generic.ListView): class TagListView(generic.ListView):
model = Tags model = Tag
class AuthorDetailView(generic.DetailView): class AuthorDetailView(generic.DetailView):
model = Authors model = Author
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
# Call the base implementation first to get the context # Call the base implementation first to get the context
context = super(AuthorDetailView, self).get_context_data(**kwargs) context = super(AuthorDetailView, self).get_context_data(**kwargs)
# Create any data and add it to the context # Create any data and add it to the context
books = BooksAuthorsLink.objects.filter(author=context["object"].id) books = BookAuthorLink.objects.filter(author=context["object"].id)
context['books'] = context['books'] = sorted( context['books'] = sorted(
[b.book for b in books.all()], key=lambda x: x.title) [b.book for b in books.all()], key=lambda x: x.title)
return context return context
class BookDetailView(generic.DetailView): class BookDetailView(generic.DetailView):
model = Books model = Book
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
# Call the base implementation first to get the context # Call the base implementation first to get the context
context = super(BookDetailView, self).get_context_data(**kwargs) context = super(BookDetailView, self).get_context_data(**kwargs)
# Create any data and add it to the context # Create any data and add it to the context
try: try:
context['comment'] = Comments.objects.get( context['comment'] = Comment.objects.get(
book=context["object"].id).text book=context["object"].id).text
except: except:
pass pass
@ -73,30 +77,30 @@ class BookDetailView(generic.DetailView):
class PublisherDetailView(generic.DetailView): class PublisherDetailView(generic.DetailView):
model = Publishers model = Publisher
class RatingDetailView(generic.DetailView): class RatingDetailView(generic.DetailView):
model = Ratings model = Rating
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
# Call the base implementation first to get the context # Call the base implementation first to get the context
context = super(RatingDetailView, self).get_context_data(**kwargs) context = super(RatingDetailView, self).get_context_data(**kwargs)
# Create any data and add it to the context # Create any data and add it to the context
books = BooksRatingsLink.objects.filter(rating=context["object"].id) books = BookRatingLink.objects.filter(rating=context["object"].id)
context['books'] = sorted( context['books'] = sorted(
[b.book for b in books.all()], key=lambda x: x.title) [b.book for b in books.all()], key=lambda x: x.title)
return context return context
class TagDetailView(generic.DetailView): class TagDetailView(generic.DetailView):
model = Tags model = Tag
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
# Call the base implementation first to get the context # Call the base implementation first to get the context
context = super(TagDetailView, self).get_context_data(**kwargs) context = super(TagDetailView, self).get_context_data(**kwargs)
# Create any data and add it to the context # Create any data and add it to the context
books = BooksTagsLink.objects.filter(tag=context["object"].id) books = BookTagLink.objects.filter(tag=context["object"].id)
context['books'] = sorted( context['books'] = sorted(
[b.book for b in books.all()], key=lambda x: x.title) [b.book for b in books.all()], key=lambda x: x.title)
return context return context