diff --git a/bookwyrm/models/shelf.py b/bookwyrm/models/shelf.py
index c578f082..320d495d 100644
--- a/bookwyrm/models/shelf.py
+++ b/bookwyrm/models/shelf.py
@@ -1,5 +1,6 @@
""" puttin' books on shelves """
import re
+from django.core.cache import cache
from django.core.exceptions import PermissionDenied
from django.db import models
from django.utils import timezone
@@ -94,8 +95,15 @@ class ShelfBook(CollectionItemMixin, BookWyrmModel):
def save(self, *args, **kwargs):
if not self.user:
self.user = self.shelf.user
+ if self.id and self.user.local:
+ cache.delete(f"book-on-shelf-{self.book.id}-{self.shelf.id}")
super().save(*args, **kwargs)
+ def delete(self, *args, **kwargs):
+ if self.id and self.user.local:
+ cache.delete(f"book-on-shelf-{self.book.id}-{self.shelf.id}")
+ super().delete(*args, **kwargs)
+
class Meta:
"""an opinionated constraint!
you can't put a book on shelf twice"""
diff --git a/bookwyrm/templates/snippets/shelve_button/shelve_button.html b/bookwyrm/templates/snippets/shelve_button/shelve_button.html
index 38f6be38..37c57fc2 100644
--- a/bookwyrm/templates/snippets/shelve_button/shelve_button.html
+++ b/bookwyrm/templates/snippets/shelve_button/shelve_button.html
@@ -6,8 +6,9 @@
{% with book.id|uuid as uuid %}
{% active_shelf book as active_shelf %}
{% latest_read_through book request.user as readthrough %}
+{% with active_shelf_book=active_shelf.book %}
- {% if switch_mode and active_shelf.book != book %}
+ {% if switch_mode and active_shelf_book != book %}
{% include 'snippets/switch_edition_button.html' with edition=book size='is-small' %}
@@ -20,16 +21,17 @@
{% join "want_to_read" uuid as modal_id %}
-{% include 'snippets/reading_modals/want_to_read_modal.html' with book=active_shelf.book id=modal_id class="" %}
+{% include 'snippets/reading_modals/want_to_read_modal.html' with book=active_shelf_book id=modal_id class="" %}
{% join "start_reading" uuid as modal_id %}
-{% include 'snippets/reading_modals/start_reading_modal.html' with book=active_shelf.book id=modal_id class="" %}
+{% include 'snippets/reading_modals/start_reading_modal.html' with book=active_shelf_book id=modal_id class="" %}
{% join "finish_reading" uuid as modal_id %}
-{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf.book id=modal_id readthrough=readthrough class="" %}
+{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf_book id=modal_id readthrough=readthrough class="" %}
{% join "progress_update" uuid as modal_id %}
-{% include 'snippets/reading_modals/progress_update_modal.html' with book=active_shelf.book id=modal_id readthrough=readthrough class="" %}
+{% include 'snippets/reading_modals/progress_update_modal.html' with book=active_shelf_book id=modal_id readthrough=readthrough class="" %}
+{% endwith %}
{% endwith %}
{% endif %}
diff --git a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html
index 0b36ddbb..15e2bb51 100644
--- a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html
+++ b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html
@@ -38,7 +38,7 @@