summaryrefslogtreecommitdiff
path: root/app/books
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2014-05-23 20:46:53 -0400
committerluxagraf <sng@luxagraf.net>2014-05-23 20:46:53 -0400
commit317a8508fe320c34a4d39a76ffbfa24e5ca8c4f9 (patch)
treea981cd1a676ce8fce623b8bcec8bdb44f7bcde08 /app/books
parent8eb15a5a3c6e2ee1e1e839f14775583e85e389ba (diff)
added images to books and imported books from stuff model
Diffstat (limited to 'app/books')
-rw-r--r--app/books/admin.py2
-rw-r--r--app/books/models.py17
2 files changed, 13 insertions, 6 deletions
diff --git a/app/books/admin.py b/app/books/admin.py
index 3f222d8..6ba03ff 100644
--- a/app/books/admin.py
+++ b/app/books/admin.py
@@ -3,7 +3,7 @@ from .models import Book, BookHighlight
class BookAdmin(admin.ModelAdmin):
- list_display = ('title', 'isbn', 'author_name', 'read_date')
+ list_display = ('title', 'admin_thumbnail', 'isbn', 'author_name', 'read_date')
class BookHighlightAdmin(admin.ModelAdmin):
diff --git a/app/books/models.py b/app/books/models.py
index 7af5d5c..cfa8379 100644
--- a/app/books/models.py
+++ b/app/books/models.py
@@ -1,4 +1,6 @@
from django.db import models
+from django.utils.encoding import force_text
+from django.conf import settings
from django.template.defaultfilters import slugify
from taggit.managers import TaggableManager
@@ -10,13 +12,9 @@ class Book(models.Model):
year_pub = models.CharField(max_length=4, blank=True, null=True)
read_date = models.DateTimeField()
isbn = models.CharField(max_length=100, blank=True, null=True)
-
body_html = models.TextField(null=True, blank=True)
-
url = models.CharField(max_length=200, blank=True, null=True)
-
- #tags = TaggableManager(blank=True, null=True)
- tags = models.CharField(max_length=200, blank=True, null=True)
+ tags = TaggableManager()
RATINGS = (
('1', "1 Star"),
('2', "2 Stars"),
@@ -26,6 +24,7 @@ class Book(models.Model):
)
rating = models.CharField(max_length=1, choices=RATINGS, null=True)
enable_comments = models.BooleanField(default=False)
+ image = models.FileField(upload_to='book-covers/', null=True, blank=True)
class Meta:
ordering = ('-read_date',)
@@ -33,6 +32,14 @@ class Book(models.Model):
def __str__(self):
return self.title
+ def get_image_url(self):
+ return '/media/%s' % (self.image)
+
+ 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
+ admin_thumbnail.short_description = 'Thumbnail'
+
def save(self, *args, **kwargs):
self.slug = slugify(self.title[:50])
super(Book, self).save()