From 0682117a0657987a550e187895888e2f089ae3b5 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 9 Feb 2021 12:07:45 -0800 Subject: [PATCH] delete and re-add shelf books in switch edition --- bookwyrm/views/books.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bookwyrm/views/books.py b/bookwyrm/views/books.py index 550c55456..2655bebba 100644 --- a/bookwyrm/views/books.py +++ b/bookwyrm/views/books.py @@ -211,9 +211,14 @@ def switch_edition(request): shelf__user=request.user ) for shelfbook in shelfbooks.all(): - # TODO: this needs to be a delete and re-create - shelfbook.book = new_edition - shelfbook.save() + with transaction.atomic(): + models.ShelfBook.objects.create( + created_date=shelfbook.created_date, + user=shelfbook.user, + shelf=shelfbook.shelf, + book=new_edition + ) + shelfbook.delete() readthroughs = models.ReadThrough.objects.filter( book__parent_work=new_edition.parent_work,