From 2f38af4faa39916b6f963b42472c656dd87d8b4e Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sat, 16 Oct 2021 06:59:07 +1100 Subject: [PATCH] Revert "clean up List db queries" This reverts commit 41f27a4a66a5452031f2840544a5c93524946f67. I forgot that update() can only be done on a query result, not on an object, so we will need to go back to querying in order to update rather than saving. --- bookwyrm/models/list.py | 7 ++++++- bookwyrm/views/list.py | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bookwyrm/models/list.py b/bookwyrm/models/list.py index 3d8c5ae14..9b05c81b5 100644 --- a/bookwyrm/models/list.py +++ b/bookwyrm/models/list.py @@ -101,10 +101,15 @@ class List(OrderedCollectionMixin, BookWyrmModel): def remove_from_group(cls, owner, user): """remove a list from a group""" - cls.objects.filter(group__user=owner, user=user).all().update( + memberships = GroupMember.objects.filter(group__user=owner, user=user).all() + + for membership in memberships: + # remove this user's group-curated lists from the group + cls.objects.filter(group=membership.group, user=membership.user).update( group=None, curation="closed" ) + class ListItem(CollectionItemMixin, BookWyrmModel): """ok""" diff --git a/bookwyrm/views/list.py b/bookwyrm/views/list.py index cc49f009c..5dae128e6 100644 --- a/bookwyrm/views/list.py +++ b/bookwyrm/views/list.py @@ -58,7 +58,7 @@ class Lists(View): book_list = form.save() # list should not have a group if it is not group curated if not book_list.curation == "group": - book_list.update(group=None) + models.List.objects.filter(id=book_list.id).update(group=None) return redirect(book_list.local_path) @@ -193,7 +193,7 @@ class List(View): return redirect("list", book_list.id) book_list = form.save() if not book_list.curation == "group": - book_list.update(group=None) + models.List.objects.filter(id=book_list.id).update(group=None) return redirect(book_list.local_path)