Не отправляет в базу данных комментарий
Изучаю django, но даже с примера почему-то не работает
Модель
class Comment(models.Model):
post = models.ForeignKey(Post, related_name='comments',on_delete=models.CASCADE)
name = models.CharField(max_length=80)
email = models.EmailField()
body = models.TextField()
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
active = models.BooleanField(default=True)
Форма
class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = ('name', 'email', 'body')
Вьюшка
def post_detail(request, post_id):
try:
post = Post.objects.get(id=post_id)
except:
post = ""
# return render(request, 'blog/post/detail.html', {"post":post})
comments = post.comments.filter(active=True)
if request.method == 'POST':
comment_form = CommentForm(data=request.POST)
if comment_form.is_valid():
new_comment = comment_form.save(commit=False)
new_comment.post = post
new_comment.save()
else:
comment_form = CommentForm()
return render(request,
'blog/post/detail.html',
{'post': post,
'comments': comments,
'comment_form': comment_form})
Код на странице
<form action="." method="post">
{{ comment_form.as_p }}
{% csrf_token %}
<p><input type="submit" name="sumbit" value="Add comment"></p>
</form>
payment_request = PaymentQiwi.objects.create(personId=personId, provider=provider, sum_amount=sum_amount, txnId=txnId, status='0', comment=comment)
message_id = message['message_id']
user_id = message['from']['id']
text = message['text']
first_name = message['from']['first_name']
last_name = message['from']['last_name']
User.objects.update_or_create(
tg_user_id=user_id,
tg_user_first_name=first_name,
tg_user_last_name=last_name)
Message.objects.create(
message_id=message_id,
user=User.objects.get(tg_user_id=user_id), text=text)
payment_request = PaymentQiwi.objects.create(personId=personId, provider=provider, sum_amount=sum_amount, txnId=txnId, status='0', comment=comment)
# Плюсуем баланс
user.balance = user.balance + payment_sum
user.save(update_fields=["balance"])
# Плюсуем бонус
user.bonus_balance = user.bonus_balance + payment_sum / 100 * 3
user.save(update_fields=["bonus_balance"])
newbonus = payment_sum / 100 * 3
payment_request = PaymentQiwi.objects.create(personId=personId, provider=provider, sum_amount=sum_amount, txnId=txnId, status='2', comment=comment)