Toggle favorite without losing postion in catalog

This commit is contained in:
Raelon Masters
2020-07-21 23:46:32 -04:00
parent 5ebaa22ee4
commit 632976328e
2 changed files with 4 additions and 8 deletions

View File

@@ -74,8 +74,8 @@ $(document).ready(function(){
$('#btn_login').on('click', function(){
$('#hdr_nav_login').toggle();
});
$('.favorite_action').on('click', toggle_favorite(){
$('.favorite_action').on('click', function(){
$(this).toggleClass('favorite');
});
$('#sortlist').change(function () {
var optionSelected = $(this).find("option:selected");
@@ -105,7 +105,3 @@ function resize_search(win_width){
}
}
function toggle_favorite($(this)){
custom_log('Favorite book by _pk'+$(this));
}

View File

@@ -233,11 +233,11 @@ def favorite(request, pk):
_d = Favorites.objects.filter(user=request.user, book=Books.objects.get(pk=pk))
if len(_d) == 1:
_d.delete()
return redirect('home')
return HttpResponse(status=204)
_f = Favorites(book=Books.objects.get(pk=pk))
_f.user = request.user
_f.save()
return redirect('home')
return HttpResponse(status=204)
def share(request, pk):