def post(self, request): bf = BookForm(renderer=request, data=request.POST) if bf.is_valid(): new_book = bf.save(commit=False) new_book.slug = slugify(bf.cleaned_data['title']) new_book.save() new_book.author.add(request.user) bf.save_m2m() return redirect('hello')
def post(self, request): book = BookForm(data=request.POST) if book.is_valid(): nb = book.save(commit=False) nb.slug = slugify(nb.title) try: nb.save() except IntegrityError: nb.slug += datetime.now().strftime("%Y:%m:%d:%H:%M:%S:%f") nb.save() nb.author.add(request.user) book.save_m2m() return redirect('hello') return redirect('add_book')
def post(self, request, book_slug): book = Book.objects.get(slug=book_slug) bf = BookForm(instance=book, data=request.POST) if bf.is_valid(): bf.save() return redirect("hello") # class AddLikeAjax(View): # def post(self, request): # if request.user.is_authenticated: # cl_id = request.POST['cl_id'][3:] # flag = CommentLike(user=request.user, comment_id=cl_id).save() # comment = Comment.objects.get(id=cl_id) # return JsonResponse({"ok": True, # 'count_like': comment.cached_like, # 'flag': flag, # 'user': request.user.username # }) # return JsonResponse({"ok": False}) # # # class AddRateAjax(View): # def post(self, request): # if request.user.is_authenticated: # book_id = request.POST['book_id'] # rate = request.POST['book_rate'] # bl = BookLike(user=request.user, book_id=book_id, rate=rate) # flag = bl.save() # bl.book.refresh_from_db() # return JsonResponse({'user': request.user.username, "flag": flag, 'cached_rate': bl.book.cached_rate, 'rate': bl.rate }) # return JsonResponse({"ok": False}) # # # class DeleteCommentAjax(View): # def delete(self, request, comment_id): # if request.user.is_authenticated: # Comment.objects.filter(id=comment_id, user=request.user).delete() # return JsonResponse({"ok": False}) # # # class AddNewBookAjax(View): # def post(self): # pass
def post(self, request, book_slug): book = Book.objects.get(slug=book_slug) bf = BookForm(instance=book, data=request.POST) if bf.is_valid(): bf.save() return redirect('hello')