есть 2 класса модели:
class ForumModel(models.Model):
name = models.CharField(max_length=30)
title = models.CharField(max_length=100)
text = models.TextField()
def __str__(self):
return self.title
class CommentModel(models.Model):
comment_text = models.TextField()
comment_forum = models.ForeignKey(ForumModel, null=True)
def __str__(self):
return self.comment_text
Views(title):
def title(request, num_title):
article = ForumModel.objects.get(id=num_title)
context = {'title': article.title, 'name': article.name, 'text': article.text, 'id': num_title, 'form': CommentForm(), 'all_comments': CommentModel.objects.all()}
if request.POST:
com = request.POST.get('comment', '')
_id = num_title
new_com = CommentModel(comment_text=com, comment_forum_id=_id)
new_com.save()
return HttpResponseRedirect('/forum/%s/' % _id)
return render(request, 'title.html', context)
Так же есть вьюха для самого форума и шаблоны. Суть в следующем:
- создал форум для сайта
- на урле форума вьюха форума отображает все статьи
- когда открываешь любую статью начинает работать views(title)
- все без ошибок, но когда ввожу коммент и жму отправить, он не отправляется=(
Если нужен будет шаблон, или что-то еще пишите, вышлю. Зараннее спасибо!