ЗАДАЮ ВОПРОС ПОВТОРНО, Т.К НЕ МОГУ НАЙТИ РЕШЕНИЕ УЖЕ ВТОРОЙ ДЕНЬ!!!
На странице комментарии не отображаются, но если добавить через админку, то все окей.
Cleaned data
возвращает правильный словарь
views.py
def more_about_question(request, q_slug):
more_q = get_object_or_404(Questions, slug=q_slug)
answer = Answer.objects.filter(post=more_q) #обращаемся к полю пост, которое равно посту
if request.method == 'POST':
answer_form = AnswerForm(data=request.POST)
if answer_form.is_valid():
print(answer_form.cleaned_data)
ans = answer_form.save(commit=False)
ans.more_q = more_q
ans.save()
else:
answer_form = AnswerForm()
dict = {
'menu':menu,
'more_q':more_q,
'title':'Вопрос',
'answer_form':answer_form,
'answer':answer
}
return render(request, 'blog/more_q.html', dict)
шаблон
{% extends 'blog/base.html' %}
{% block more_q %}
<td valign="top" class="content">
<!-- Так выглядит вопрос(запись)-->
<div class="square">
<h5 class="category">{{more_q.q_cat}}</h5>
<h1 class="q_name">{{more_q.q_name}}</h1>
{% autoescape off %}
<p class="q_text">{{more_q.q_text}}</p>
{% endautoescape %}
</div>
<!--Подсчет кол-ва ответов на вопрос-->
{% with answer.count as total_answer %}
<h2>
Ответы - {{ total_answer }}
</h2>
{% endwith %}
<!-- форма для заполнения ответов -->
<h3>Add a new comment</h3>
<form method="post">
{% csrf_token %}
{{ answer_form.as_p }}
<p><input type="submit" value="Add comment"></p>
</form>
<!--Отображаение всех ответов-->
{% for ans in answer %}
<div class="answer">
<p>
Ответ от {{ ans.name }}
{{ ans.created }}
</p>
{{ ans.text|linebreaks }}
</div>
{% empty %}
<p>There are no comments yet.</p>
{% endfor %}
</td>
{% endblock %}