Invalidate active_shelf when switching editions

This commit is contained in:
Adeodato Simó 2024-01-13 18:55:13 +01:00
parent b04ebe397b
commit eb13eb9882
No known key found for this signature in database
GPG key ID: CDF447845F1A986F

View file

@ -3,6 +3,7 @@ from functools import reduce
import operator import operator
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.core.cache import cache as django_cache
from django.core.paginator import Paginator from django.core.paginator import Paginator
from django.db import transaction from django.db import transaction
from django.db.models import Q from django.db.models import Q
@ -103,4 +104,10 @@ def switch_edition(request):
readthrough.book = new_edition readthrough.book = new_edition
readthrough.save() readthrough.save()
django_cache.delete_many(
[
f"active_shelf-{request.user.id}-{book_id}"
for book_id in new_edition.parent_work.editions.values_list("id", flat=True)
]
)
return redirect(f"/book/{new_edition.id}") return redirect(f"/book/{new_edition.id}")