Esempio n. 1
0
 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')
Esempio n. 2
0
 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')