diff options
author | luxagraf <sng@luxagraf.net> | 2018-03-13 13:30:37 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2018-03-13 13:30:37 -0500 |
commit | 83dd70783a8affeb312854fa50ee4c7f97cf797a (patch) | |
tree | 970c46931290eeacce13781e571aaddc04688180 /app | |
parent | fd379786ea1a2a6d01cc388bc25938688b65388f (diff) |
fixed some bugs in books and got it PEP8 compliant
Diffstat (limited to 'app')
-rw-r--r-- | app/books/admin.py | 6 | ||||
-rw-r--r-- | app/books/models.py | 12 | ||||
-rw-r--r-- | app/books/urls.py | 7 |
3 files changed, 12 insertions, 13 deletions
diff --git a/app/books/admin.py b/app/books/admin.py index 29a885f..8d94651 100644 --- a/app/books/admin.py +++ b/app/books/admin.py @@ -2,6 +2,7 @@ from django.contrib import admin from .models import Book, BookHighlight +@admin.register(Book) class BookAdmin(admin.ModelAdmin): list_display = ('title', 'admin_thumbnail', 'rating', 'isbn', 'author_name', 'read_date', 'publish_date') search_fields = ['title', 'body_markdown'] @@ -10,8 +11,7 @@ class BookAdmin(admin.ModelAdmin): class Media: js = ('next-prev-links.js',) + +@admin.register(BookHighlight) class BookHighlightAdmin(admin.ModelAdmin): list_display = ('book', 'page', 'date_added') - -admin.site.register(Book, BookAdmin) -admin.site.register(BookHighlight, BookHighlightAdmin) diff --git a/app/books/models.py b/app/books/models.py index c3c15f4..59f0ae3 100644 --- a/app/books/models.py +++ b/app/books/models.py @@ -1,6 +1,8 @@ +import datetime from django.db import models from django.urls import reverse -from django.utils.encoding import force_text +from django.apps import apps +from django.utils.html import format_html from django.conf import settings from django.template.defaultfilters import slugify @@ -25,7 +27,6 @@ class Book(models.Model): publish_date = models.CharField(max_length=40, blank=True, null=True) publish_place = models.CharField(max_length=100, blank=True, null=True) openlib_url = models.CharField(max_length=400, blank=True, null=True) - amazon_url = models.CharField(max_length=400, blank=True, null=True) RATINGS = ( ('1', "1 Star"), ('2', "2 Stars"), @@ -60,19 +61,18 @@ class Book(models.Model): @property def get_previous_admin_url(self): n = self.get_previous_by_pub_date() - return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[n.id] ) + return reverse('admin:%s_%s_change' % (self._meta.app_label, self._meta.model_name), args=[n.id]) @property def get_next_admin_url(self): model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name) try: - return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[self.get_next_by_pub_date().pk] ) + return reverse('admin:%s_%s_change' % (self._meta.app_label, self._meta.model_name), args=[self.get_next_by_pub_date().pk]) except model.DoesNotExist: return '' def admin_thumbnail(self): - return force_text('<a href=""><img src="%s" width="100" style="width:100px"></a>' % (self.get_image_url())) - admin_thumbnail.allow_tags = True + return format_html('<img src="%s" width="100" style="width:100px" />' % (self.get_image_url())) admin_thumbnail.short_description = 'Thumbnail' def save(self, *args, **kwargs): diff --git a/app/books/urls.py b/app/books/urls.py index 4855149..e6737bb 100644 --- a/app/books/urls.py +++ b/app/books/urls.py @@ -1,5 +1,4 @@ from django.urls import path, re_path -from django.views.generic.base import RedirectView from . import views @@ -12,9 +11,9 @@ urlpatterns = [ name="list" ), path( - r'', - views.BookListView.as_view(), - {'page':1}, + r'', + views.BookListView.as_view(), + {'page': 1}, name="list" ), path( |