summaryrefslogtreecommitdiff
path: root/app/books
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2018-02-05 13:38:59 -0600
committerluxagraf <sng@luxagraf.net>2018-02-05 13:38:59 -0600
commit3398e7349e2bafddaa491c01f4c16c6dae14cd00 (patch)
tree0ae25201ce6fc50146dff819b03819ddce148cfe /app/books
parentad112641f01a0fd36d0b738b6903dea3eadbf000 (diff)
abstracted the next prev links into utils so now they work for every
model that implements a get_%S_admin_link method and loads the JS
Diffstat (limited to 'app/books')
-rw-r--r--app/books/admin.py2
-rw-r--r--app/books/models.py13
2 files changed, 15 insertions, 0 deletions
diff --git a/app/books/admin.py b/app/books/admin.py
index 1896067..29a885f 100644
--- a/app/books/admin.py
+++ b/app/books/admin.py
@@ -7,6 +7,8 @@ class BookAdmin(admin.ModelAdmin):
search_fields = ['title', 'body_markdown']
list_filter = ('rating', 'read_date')
+ class Media:
+ js = ('next-prev-links.js',)
class BookHighlightAdmin(admin.ModelAdmin):
list_display = ('book', 'page', 'date_added')
diff --git a/app/books/models.py b/app/books/models.py
index f888480..ebd3a2a 100644
--- a/app/books/models.py
+++ b/app/books/models.py
@@ -56,6 +56,19 @@ class Book(models.Model):
def ratings_range(cls):
return range(1, 6)
+ @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] )
+
+ @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] )
+ 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