Exemplo n.º 1
0
 def post(self, request, slug):
     if request.user.is_authenticated:
         book = Book.objects.get(slug=slug)
         if request.user in book.authors.all():
             bf = BookForm(instance=book, data=request.POST)
             if bf.is_valid():
                 bf.save(commit=True)
     return redirect('the-main-page')
Exemplo n.º 2
0
 def post(self, request):
     if request.user.is_authenticated:
         bf = BookForm(request.POST, request.FILES)
         if bf.is_valid():
             book = bf.save(commit=True)
             book.authors.add(request.user)
             book.save()
             return redirect("the-main-page")
     messages.error(request,
                    "книга с таким slug уже существует!!! измените slug")
     return redirect("the-main-page")