X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/8676651fe1b1de0e033e644ddb93c53f8c9402d0..7d801e715b70774ff4f2a238045385e093701a8e:/apps/catalogue/views.py?ds=inline diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 9ae50515d..c9d6ab227 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -188,8 +188,18 @@ def book_sets(request, slug): if request.method == 'POST': form = forms.ObjectSetsForm(book, request.user, request.POST) if form.is_valid(): - book.tags = ([models.Tag.objects.get(pk=id) for id in form.cleaned_data['set_ids']] + - list(book.tags.filter(~Q(category='set') | ~Q(user=request.user)))) + old_shelves = list(book.tags.filter(category='set')) + new_shelves = [models.Tag.objects.get(pk=id) for id in form.cleaned_data['set_ids']] + + for shelf in [shelf for shelf in old_shelves if shelf not in new_shelves]: + shelf.book_count -= 1 + shelf.save() + + for shelf in [shelf for shelf in new_shelves if shelf not in old_shelves]: + shelf.book_count += 1 + shelf.save() + + book.tags = new_shelves + list(book.tags.filter(~Q(category='set') | ~Q(user=request.user))) if request.is_ajax(): return HttpResponse('
PóÅki zostaÅy zapisane.
') else: @@ -211,6 +221,9 @@ def remove_from_shelf(request, shelf, book): models.Tag.objects.remove_tag(book, shelf) + shelf.book_count -= 1 + shelf.save() + return HttpResponse('Usunieto')