From a7e369a4c170f0c480b8d850b7c488db62014c70 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 31 May 2022 21:29:29 -0400 Subject: [PATCH] option to create new collection when add from detail page --- collection/templates/add_to_list.html | 3 ++- collection/views.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/collection/templates/add_to_list.html b/collection/templates/add_to_list.html index 56ef0611..8ce1cae8 100644 --- a/collection/templates/add_to_list.html +++ b/collection/templates/add_to_list.html @@ -29,8 +29,9 @@ {% csrf_token %}
diff --git a/collection/views.py b/collection/views.py index 0a3c2387..c2150008 100644 --- a/collection/views.py +++ b/collection/views.py @@ -407,6 +407,9 @@ def add_to_list(request, type, id): } ) else: - collection = Collection.objects.filter(owner=request.user, id=request.POST.get('collection_id')).first() + cid = int(request.POST.get('collection_id', default=0)) + if not cid: + cid = Collection.objects.create(owner=request.user, title=f'{request.user.username}的收藏单').id + collection = Collection.objects.filter(owner=request.user, id=cid).first() collection.append_item(item, request.POST.get('comment')) return HttpResponseRedirect(request.META.get('HTTP_REFERER'))