Ребята привет, изучаю Django, столкнулся с проблемой нуждаюсь в помощи <div class="container">
{% if request.user.user.flan_verification %}
<form method="post" action="{% url 'create_news' %}">
{% csrf_token %}
<h5>Выберите тэг</h5>
{{form.as_p}}
<h5> Создайте свой тэг </h5>
{{tag_form.as_p}}
<button class="btn-registration" type="submit"> отправить </button>
</form>
{% else %}
<h6 style="font-size: 20px; color: red;"> Вы не имеете прав на создание новости </h6>
{% endif %}
</div>
{% endblock %} teamplate class VerificationUsers(generic.TemplateView):
template_name = 'app_users/create_news.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
form = NewsCreationForm()
tag_form = TagCreationForm()
context['form'] = form
context['tag_form'] = tag_form
return context
def post(self, request, **kwargs):
context = super().get_context_data(**kwargs)
form = NewsCreationForm(
request.POST)
tag_form = TagCreationForm(
request.POST)
print('cleaned_data ---', type(tag_form))
if form.is_valid():
cleaned_data = form.cleaned_data
news = News.objects.create(
title=cleaned_data['title'],
content=cleaned_data['content'],
)
print(cleaned_data['tag'] is True)
if cleaned_data['tag']:
tag = cleaned_data['tag'][0]
news.tag.add(tag)
news.save()
else:
if tag_form.is_valid():
tag_form = tag_form.cleaned_data['tag_form']
news.tag.add(tag_form)
news.save()
user = Profile.objects.get(user_id=
request.user.id)
if user.count_publish is not None:
user.count_publish += 1
else:
user.count_publish = 1
user.save()
else:
form = NewsCreationForm()
context['form'] = form
return self.render_to_response(context={'form': form}) views