From 5fccb991a7a15da78ad2ed4d2ca1e753b14aae37 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 26 Sep 2021 18:28:16 +1000 Subject: [PATCH] remove list from group when changing curation Allows 'group' to be blank when saving a list. Removes the 'group' field when saving a list with curation other than 'group' - this stops the list "sticking" to a group after it is changed from group curation to something else. --- bookwyrm/models/list.py | 3 ++- bookwyrm/templates/lists/form.html | 8 ++------ bookwyrm/views/list.py | 7 +++---- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/bookwyrm/models/list.py b/bookwyrm/models/list.py index b73d77086..75f34b9e8 100644 --- a/bookwyrm/models/list.py +++ b/bookwyrm/models/list.py @@ -37,7 +37,8 @@ class List(OrderedCollectionMixin, BookWyrmModel): group = models.ForeignKey( "Group", on_delete=models.CASCADE, - null=True + default=None, + blank=True ) books = models.ManyToManyField( "Edition", diff --git a/bookwyrm/templates/lists/form.html b/bookwyrm/templates/lists/form.html index 0019520e8..d2f17d63b 100644 --- a/bookwyrm/templates/lists/form.html +++ b/bookwyrm/templates/lists/form.html @@ -37,20 +37,16 @@ {% trans "Group" %}

{% trans "Group members can add to and remove from this list" %}

- - - - {% if user_groups %} {% csrf_token %}
diff --git a/bookwyrm/views/list.py b/bookwyrm/views/list.py index 9ef027538..fb224cdf5 100644 --- a/bookwyrm/views/list.py +++ b/bookwyrm/views/list.py @@ -62,10 +62,6 @@ class Lists(View): def post(self, request): """create a book_list""" form = forms.ListForm(request.POST) - # TODO: here we need to take the value of the group (the group.id) - # and fetch the actual group to add to the DB - # but only if curation type is 'group' other wise the value of - # group is None if not form.is_valid(): return redirect("lists") book_list = form.save() @@ -208,6 +204,9 @@ class List(View): if not form.is_valid(): return redirect("list", book_list.id) book_list = form.save() + if not book_list.curation == "group": + book_list.group = None + book_list.save() return redirect(book_list.local_path)