def bookmark_post(request): if not request.is_ajax(): return HttpResponse("you cant access here") post_id=request.POST['id'] ret = {"success": 0} try: bookmark = BookMark.objects.get(post__pk=post_id) except BookMark.DoesNotExist: BookMark.objects.create(user=request.user,post=Posting.objects.get(pk=post_id)) #success if new bookmark is created ret['success']=1 else: BookMark.delete(bookmark) return HttpResponse(simplejson.dumps(ret), content_type="application/json")
def unbookmark(request): bm_id=request.POST.get("bookmark_id",None) if bm_id: bookmark = BookMark.objects.get(post__pk=bm_id) BookMark.delete(bookmark) return redirect('bookmark_listView')