Renamed models like how Django does it, fixed commens on book template
This commit is contained in:
parent
99a74b75a9
commit
62b9dfd94f
@ -1,16 +1,16 @@
|
||||
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.
|
||||
|
||||
@admin.register(Authors)
|
||||
@admin.register(Author)
|
||||
class AuthorAdmin(admin.ModelAdmin):
|
||||
list_display = (["name"])
|
||||
|
||||
@admin.register(Languages)
|
||||
@admin.register(Language)
|
||||
class LanguageAdmin(admin.ModelAdmin):
|
||||
list_display = (["id", "lang_code"])
|
||||
|
||||
@admin.register(Publishers)
|
||||
@admin.register(Publisher)
|
||||
class PublisherAdmin(admin.ModelAdmin):
|
||||
list_display = (["id","name"])
|
||||
|
||||
@ -18,10 +18,10 @@ class PublisherAdmin(admin.ModelAdmin):
|
||||
class SeriesAdmin(admin.ModelAdmin):
|
||||
list_display = (["id","name"])
|
||||
|
||||
@admin.register(Tags)
|
||||
@admin.register(Tag)
|
||||
class TagAdmin(admin.ModelAdmin):
|
||||
list_display = (["id","name"])
|
||||
|
||||
@admin.register(Books)
|
||||
@admin.register(Book)
|
||||
class BookAdmin(admin.ModelAdmin):
|
||||
list_display = (["id","title", "author_sort"])
|
@ -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)
|
||||
|
@ -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):
|
||||
unique_authors = Authors.objects.all().order_by('sort')
|
||||
unique_tags = Tags.objects.all().order_by('name')
|
||||
unique_publishers = Publishers.objects.all().order_by('name')
|
||||
unique_languages = Languages.objects.all()
|
||||
unique_ratings = Ratings.objects.all().order_by('rating')
|
||||
unique_authors = Author.objects.all().order_by('sort')
|
||||
unique_tags = Tag.objects.all().order_by('name')
|
||||
unique_publishers = Publisher.objects.all().order_by('name')
|
||||
unique_languages = Language.objects.all()
|
||||
unique_ratings = Rating.objects.all().order_by('rating')
|
||||
unique_series = Series.objects.all().order_by('sort')
|
||||
|
||||
return {
|
||||
|
@ -9,7 +9,7 @@ from django.db import models
|
||||
from django.urls import reverse
|
||||
|
||||
|
||||
class Authors(models.Model):
|
||||
class Author(models.Model):
|
||||
name = models.TextField()
|
||||
sort = models.TextField(blank=True, null=True)
|
||||
link = models.TextField()
|
||||
@ -28,8 +28,8 @@ class Authors(models.Model):
|
||||
|
||||
|
||||
|
||||
class Comments(models.Model):
|
||||
book = models.ForeignKey("Books", db_column="book", on_delete=models.CASCADE)
|
||||
class Comment(models.Model):
|
||||
book = models.ForeignKey("Book", db_column="book", on_delete=models.CASCADE)
|
||||
text = models.TextField()
|
||||
|
||||
|
||||
@ -57,7 +57,7 @@ class Data(models.Model):
|
||||
]
|
||||
|
||||
|
||||
class Identifiers(models.Model):
|
||||
class Identifier(models.Model):
|
||||
book = models.IntegerField()
|
||||
type = models.TextField()
|
||||
val = models.TextField()
|
||||
@ -71,7 +71,7 @@ class Identifiers(models.Model):
|
||||
db_table = 'identifiers'
|
||||
|
||||
|
||||
class Languages(models.Model):
|
||||
class Language(models.Model):
|
||||
lang_code = models.TextField()
|
||||
|
||||
def get_absolute_url(self):
|
||||
@ -90,12 +90,12 @@ class Languages(models.Model):
|
||||
]
|
||||
|
||||
|
||||
class Publishers(models.Model):
|
||||
class Publisher(models.Model):
|
||||
name = models.TextField()
|
||||
sort = models.TextField(blank=True, null=True)
|
||||
released = models.ManyToManyField(
|
||||
"Books",
|
||||
through='BooksPublishersLink',
|
||||
"Book",
|
||||
through='BookPublisherLink',
|
||||
through_fields=('publisher', 'book'),
|
||||
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)
|
||||
def get_absolute_url(self):
|
||||
"""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()
|
||||
def get_absolute_url(self):
|
||||
"""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()
|
||||
sort = models.TextField(blank=True, null=True)
|
||||
# This field type is a guess.
|
||||
@ -186,28 +186,28 @@ class Books(models.Model):
|
||||
has_cover = models.BooleanField(blank=True, null=True)
|
||||
last_modified = models.TextField() # This field type is a guess.
|
||||
authors = models.ManyToManyField(
|
||||
Authors,
|
||||
through='BooksAuthorsLink',
|
||||
Author,
|
||||
through='BookAuthorLink',
|
||||
through_fields=('book', 'author'))
|
||||
languages = models.ManyToManyField(
|
||||
Languages,
|
||||
through='BooksLanguagesLink',
|
||||
Language,
|
||||
through='BookLanguageLink',
|
||||
through_fields=('book', 'lang_code'))
|
||||
publishers = models.ManyToManyField(
|
||||
Publishers,
|
||||
through='BooksPublishersLink',
|
||||
Publisher,
|
||||
through='BookPublisherLink',
|
||||
through_fields=('book', 'publisher'))
|
||||
series = models.ManyToManyField(
|
||||
Series,
|
||||
through='BooksSeriesLink',
|
||||
through='BookSeriesLink',
|
||||
through_fields=('book', 'series'))
|
||||
tags = models.ManyToManyField(
|
||||
Tags,
|
||||
through='BooksTagsLink',
|
||||
Tag,
|
||||
through='BookTagLink',
|
||||
through_fields=('book', 'tag'))
|
||||
ratings = models.ManyToManyField(
|
||||
Ratings,
|
||||
through='BooksRatingsLink',
|
||||
Rating,
|
||||
through='BookRatingLink',
|
||||
through_fields=('book', 'rating'))
|
||||
def get_absolute_url(self):
|
||||
"""Returns the url to access a particular instance of MyModelName."""
|
||||
@ -226,10 +226,10 @@ class Books(models.Model):
|
||||
]
|
||||
|
||||
|
||||
class BooksAuthorsLink(models.Model):
|
||||
book = models.ForeignKey(Books, db_column="book", on_delete=models.CASCADE)
|
||||
class BookAuthorLink(models.Model):
|
||||
book = models.ForeignKey(Book, db_column="book", on_delete=models.CASCADE)
|
||||
author = models.ForeignKey(
|
||||
Authors, db_column="author", on_delete=models.CASCADE)
|
||||
Author, db_column="author", on_delete=models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
@ -240,10 +240,10 @@ class BooksAuthorsLink(models.Model):
|
||||
]
|
||||
|
||||
|
||||
class BooksLanguagesLink(models.Model):
|
||||
book = models.ForeignKey(Books, db_column="book", on_delete=models.CASCADE)
|
||||
class BookLanguageLink(models.Model):
|
||||
book = models.ForeignKey(Book, db_column="book", on_delete=models.CASCADE)
|
||||
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()
|
||||
|
||||
class Meta:
|
||||
@ -256,10 +256,10 @@ class BooksLanguagesLink(models.Model):
|
||||
]
|
||||
|
||||
|
||||
class BooksPublishersLink(models.Model):
|
||||
book = models.ForeignKey(Books, db_column="book", on_delete=models.CASCADE)
|
||||
class BookPublisherLink(models.Model):
|
||||
book = models.ForeignKey(Book, db_column="book", on_delete=models.CASCADE)
|
||||
publisher = models.ForeignKey(
|
||||
Publishers, db_column="publisher", on_delete=models.CASCADE)
|
||||
Publisher, db_column="publisher", on_delete=models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
@ -271,18 +271,18 @@ class BooksPublishersLink(models.Model):
|
||||
]
|
||||
|
||||
|
||||
class BooksRatingsLink(models.Model): # TODO add this somehow
|
||||
book = models.ForeignKey(Books, db_column="book", on_delete=models.CASCADE)
|
||||
class BookRatingLink(models.Model): # TODO add this somehow
|
||||
book = models.ForeignKey(Book, db_column="book", on_delete=models.CASCADE)
|
||||
rating = models.ForeignKey(
|
||||
Ratings, db_column="rating", on_delete=models.CASCADE)
|
||||
Rating, db_column="rating", on_delete=models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = 'books_ratings_link'
|
||||
|
||||
|
||||
class BooksSeriesLink(models.Model):
|
||||
book = models.ForeignKey(Books, db_column="book", on_delete=models.CASCADE)
|
||||
class BookSeriesLink(models.Model):
|
||||
book = models.ForeignKey(Book, db_column="book", on_delete=models.CASCADE)
|
||||
series = models.ForeignKey(
|
||||
Series, db_column="series", on_delete=models.CASCADE)
|
||||
|
||||
@ -295,9 +295,9 @@ class BooksSeriesLink(models.Model):
|
||||
]
|
||||
|
||||
|
||||
class BooksTagsLink(models.Model):
|
||||
book = models.ForeignKey(Books, db_column="book", on_delete=models.CASCADE)
|
||||
tag = models.ForeignKey(Tags, db_column="tag", on_delete=models.CASCADE)
|
||||
class BookTagLink(models.Model):
|
||||
book = models.ForeignKey(Book, db_column="book", on_delete=models.CASCADE)
|
||||
tag = models.ForeignKey(Tag, db_column="tag", on_delete=models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
@ -308,7 +308,7 @@ class BooksTagsLink(models.Model):
|
||||
]
|
||||
|
||||
|
||||
# class BooksPluginData(models.Model):
|
||||
# class BookPluginData(models.Model):
|
||||
# book = models.IntegerField()
|
||||
# name = models.TextField()
|
||||
# val = models.TextField()
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
{% block content %}
|
||||
{% load static %}
|
||||
<h1>{{authors}}</h1>
|
||||
<h1>{{author}}</h1>
|
||||
|
||||
<table id="books">
|
||||
<tr>
|
@ -3,15 +3,15 @@
|
||||
{% block content %}
|
||||
{% load static %}
|
||||
<h1>Author List</h1>
|
||||
{% if authors_list %}
|
||||
{% if author_list %}
|
||||
<ul>
|
||||
{% for author in authors_list %}
|
||||
{% for author in author_list %}
|
||||
<li>
|
||||
<a href="{{ author.get_absolute_url }}">{{ author.name }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>There are no authors in the library.</p>
|
||||
<p>There are no author in the library.</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
@ -2,19 +2,19 @@
|
||||
|
||||
{% block content %}
|
||||
{% load static %}
|
||||
<h1>{{books.title}} by
|
||||
{% if books.authors %}
|
||||
{% for author in books.authors.all %}
|
||||
<h1>{{book.title}} by
|
||||
{% if book.authors %}
|
||||
{% for author in book.authors.all %}
|
||||
<a href="{{author.get_absolute_url}}">{{author.name}}</a>
|
||||
{%endfor%}
|
||||
{% else %}
|
||||
|
||||
{{books.author_sort}}
|
||||
{{book.author_sort}}
|
||||
{%endif%}
|
||||
|
||||
Published by
|
||||
{% if books.publishers %}
|
||||
{% for pub in books.publishers.all %}
|
||||
{% if book.publishers %}
|
||||
{% for pub in book.publishers.all %}
|
||||
<a href="{{pub.get_absolute_url}}">{{pub.name}}</a>
|
||||
{%endfor%}
|
||||
{% else %}
|
||||
@ -23,16 +23,16 @@
|
||||
{%endif%}
|
||||
|
||||
Tags:
|
||||
{% if books.tags %}
|
||||
{% for tag in books.tags.all %}
|
||||
{% if book.tags %}
|
||||
{% for tag in book.tags.all %}
|
||||
<a href="{{tag.get_absolute_url}}">{{tag.name}}</a>,
|
||||
{%endfor%}
|
||||
{% else %}
|
||||
{%endif%}
|
||||
|
||||
Rating:
|
||||
{% if books.ratings %}
|
||||
{% for rating in books.ratings.all %}
|
||||
{% if book.ratings %}
|
||||
{% for rating in book.ratings.all %}
|
||||
<a href="{{rating.get_absolute_url}}">{{rating}}</a>
|
||||
{%endfor%}
|
||||
{% else %}
|
||||
@ -40,8 +40,11 @@
|
||||
|
||||
<a href="{{book.publisher.get_absolute_url}}">{{book.publisher}}</a>
|
||||
</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 %}
|
@ -13,7 +13,7 @@
|
||||
<th onclick="sortTable(3)">Tags</th>
|
||||
<th onclick="sortTable(4)">Added</th>
|
||||
</tr>
|
||||
{% for book in books_list %}
|
||||
{% for book in book_list %}
|
||||
<tr>
|
||||
<td><a href="{{ book.get_absolute_url }}">{{ book.title }}</a></td>
|
||||
<td>{{book.author_sort}}</td>
|
@ -2,9 +2,9 @@
|
||||
|
||||
{% block content %}
|
||||
{% load static %}
|
||||
<h1>{{publishers}} </h1>
|
||||
<h1>{{publisher}} </h1>
|
||||
|
||||
{% if publishers.released %}
|
||||
{% if publisher.released %}
|
||||
<table id="books">
|
||||
<tr>
|
||||
<!--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(4)">Added</th>
|
||||
</tr>
|
||||
{% for book in publishers.released.all %}
|
||||
{% for book in publisher.released.all %}
|
||||
<tr>
|
||||
<td><a href="{{ book.get_absolute_url }}">{{ book.title }}</a></td>
|
||||
<td>{{book.author_sort}}</td>
|
@ -3,15 +3,15 @@
|
||||
{% block content %}
|
||||
{% load static %}
|
||||
<h1>Publishers List</h1>
|
||||
{% if publishers_list %}
|
||||
{% if publisher_list %}
|
||||
<ul>
|
||||
{% for publisher in publishers_list %}
|
||||
{% for publisher in publisher_list %}
|
||||
<li>
|
||||
<a href="{{ publisher.get_absolute_url }}">{{ publisher.name }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>There are no publishers in the library.</p>
|
||||
<p>There are no publisher in the library.</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
@ -3,7 +3,7 @@
|
||||
{% block content %}
|
||||
{% load static %}
|
||||
|
||||
<h1>{{ratings}}</h1>
|
||||
<h1>{{rating}}</h1>
|
||||
{% if books %}
|
||||
<table id="books">
|
||||
<tr>
|
||||
@ -18,7 +18,7 @@
|
||||
<tr>
|
||||
<td><a href="{{ book.get_absolute_url }}">{{ book.title }}</a></td>
|
||||
<td>{{book.author_sort}}</td>
|
||||
<td> {% for rating in book.ratings.all %}
|
||||
<td> {% for rating in book.rating.all %}
|
||||
{{rating}}
|
||||
{% endfor %}
|
||||
</td>
|
@ -3,15 +3,15 @@
|
||||
{% block content %}
|
||||
{% load static %}
|
||||
<h1>Ratings List</h1>
|
||||
{% if ratings_list %}
|
||||
{% if rating_list %}
|
||||
<ul>
|
||||
{% for rating in ratings_list %}
|
||||
{% for rating in rating_list %}
|
||||
<li>
|
||||
<a href="{{ rating.get_absolute_url }}">{{ rating.rating }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>There are no ratings in the library.</p>
|
||||
<p>There are no rating in the library.</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
@ -3,7 +3,7 @@
|
||||
{% block content %}
|
||||
{% load static %}
|
||||
|
||||
<h1>{{tags}}</h1>
|
||||
<h1>{{tag}}</h1>
|
||||
{% if books %}
|
||||
<table id="books">
|
||||
<tr>
|
||||
@ -23,7 +23,7 @@
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td>
|
||||
{% for tag in book.tags.all %}
|
||||
{% for tag in book.tag.all %}
|
||||
{{tag}},
|
||||
{% endfor %}
|
||||
</td>
|
@ -3,15 +3,15 @@
|
||||
{% block content %}
|
||||
{% load static %}
|
||||
<h1>Tags List</h1>
|
||||
{% if tags_list %}
|
||||
{% if tag_list %}
|
||||
<ul>
|
||||
{% for tag in tags_list %}
|
||||
{% for tag in tag_list %}
|
||||
<li>
|
||||
<a href="{{ tag.get_absolute_url }}">{{ tag.name }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>There are no tags in the library.</p>
|
||||
<p>There are no tag in the library.</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
@ -1 +0,0 @@
|
||||
from . import custom
|
@ -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()
|
@ -1,68 +1,72 @@
|
||||
from django.shortcuts import render
|
||||
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 .forms import SearchForm
|
||||
from django.db import models
|
||||
from django.db.models import Q
|
||||
|
||||
|
||||
class SearchView(generic.TemplateView):
|
||||
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
|
||||
# it is
|
||||
model = Books
|
||||
model = Book
|
||||
template_name = 'results.html'
|
||||
def get_queryset(self): # new
|
||||
|
||||
def get_queryset(self): # new
|
||||
title = self.request.GET.get('title')
|
||||
author = self.request.GET.get('author')
|
||||
return Books.objects.filter(
|
||||
return Book.objects.filter(
|
||||
Q(sort__icontains=title) and Q(author_sort__icontains=author)
|
||||
)
|
||||
|
||||
|
||||
class AuthorListView(generic.ListView):
|
||||
model = Authors
|
||||
model = Author
|
||||
|
||||
|
||||
class BookListView(generic.ListView):
|
||||
model = Books
|
||||
model = Book
|
||||
|
||||
|
||||
class PublisherListView(generic.ListView):
|
||||
model = Publishers
|
||||
model = Publisher
|
||||
|
||||
|
||||
class RatingListView(generic.ListView):
|
||||
model = Ratings
|
||||
model = Rating
|
||||
|
||||
|
||||
class TagListView(generic.ListView):
|
||||
model = Tags
|
||||
model = Tag
|
||||
|
||||
|
||||
class AuthorDetailView(generic.DetailView):
|
||||
model = Authors
|
||||
model = Author
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
# Call the base implementation first to get the context
|
||||
context = super(AuthorDetailView, self).get_context_data(**kwargs)
|
||||
# Create any data and add it to the context
|
||||
books = BooksAuthorsLink.objects.filter(author=context["object"].id)
|
||||
context['books'] = context['books'] = sorted(
|
||||
books = BookAuthorLink.objects.filter(author=context["object"].id)
|
||||
context['books'] = sorted(
|
||||
[b.book for b in books.all()], key=lambda x: x.title)
|
||||
return context
|
||||
|
||||
|
||||
class BookDetailView(generic.DetailView):
|
||||
model = Books
|
||||
model = Book
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
# Call the base implementation first to get the context
|
||||
context = super(BookDetailView, self).get_context_data(**kwargs)
|
||||
# Create any data and add it to the context
|
||||
try:
|
||||
context['comment'] = Comments.objects.get(
|
||||
context['comment'] = Comment.objects.get(
|
||||
book=context["object"].id).text
|
||||
except:
|
||||
pass
|
||||
@ -73,30 +77,30 @@ class BookDetailView(generic.DetailView):
|
||||
|
||||
|
||||
class PublisherDetailView(generic.DetailView):
|
||||
model = Publishers
|
||||
model = Publisher
|
||||
|
||||
|
||||
class RatingDetailView(generic.DetailView):
|
||||
model = Ratings
|
||||
model = Rating
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
# Call the base implementation first to get the context
|
||||
context = super(RatingDetailView, self).get_context_data(**kwargs)
|
||||
# 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(
|
||||
[b.book for b in books.all()], key=lambda x: x.title)
|
||||
return context
|
||||
|
||||
|
||||
class TagDetailView(generic.DetailView):
|
||||
model = Tags
|
||||
model = Tag
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
# Call the base implementation first to get the context
|
||||
context = super(TagDetailView, self).get_context_data(**kwargs)
|
||||
# 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(
|
||||
[b.book for b in books.all()], key=lambda x: x.title)
|
||||
return context
|
||||
|
Loading…
Reference in New Issue
Block a user