Answer the question
In order to leave comments, you need to log in
How to redirect the user to the current page?
There is a controller that is responsible for adding comments to the post
#views.py
class AddResponse(View):
"""Отклики"""
def post(self, request, pk):
form = ResponseForm(request.POST)
post = Bb.objects.get(id=pk)
if form.is_valid():
form = form.save(commit=False)
form.user = request.user
form.post = post
form.save()
return redirect('index')
class Bb(models.Model):
title = models.CharField(max_length=50, verbose_name="Суть вопроса")
content = models.TextField(null=True, blank=True, verbose_name="Детали вопроса")
rubric = models.ForeignKey('Rubric', null=True, on_delete=models.PROTECT, verbose_name="Предмет")
price = models.FloatField(null=True, blank=True, verbose_name="Максимальная цена")
published = models.DateTimeField(auto_now_add=True, db_index=True, verbose_name="Опубликовано")
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, default=User, verbose_name="Пользователь")
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question