views.py
class BookDisplay(DetailView):
model = Book
template_name = 'books/book_detail.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['form'] = WishBookForm()
return context
class WishBook(SingleObjectMixin, FormView):
form_class = WishBookForm()
template_name = 'books/book_detail.html'
model = Status
def post(self, request):
if not request.user.is_authenticated:
return HttpResponseForbidden()
self.object = self.get_object()
return super().post(request)
def get_success_url(self):
class BookDetail(View):
def get(self, request):
view = BookDisplay.as_view()
return view(request)
def post(self, request):
view = WishBook.as_view()
return view(request)
forms.py
class WishBookForm(forms.Form):
status = forms.ChoiceField(choices=Status.GIVEAWAY_STATUS[:2], initial='Cu chef de ducă')