Как придать сообщению (в форуме) тег (django-taggit) с чекбоксами?
В моем веб-форуме есть add Post
Страница, которая выглядит следующим образом:
Как я могу получить все нажатые теги как объект django-taggit или что-то подобное, затем отправить их на мой бэкенд и сохранить в базе данных? Мой views.py выглядит следующим образом:
def post_question_tags(request):
current_user = request.user
if request.method == "POST":
Post.objects.create(title = request.POST["title"], description = request.POST["description"], tags = request.POST["tags"], author = current_user)
all_tags = Tag.objects.all()
return render(request, "post_question_tags.html", {'all_tags' : all_tags, 'current_user': current_user})
Мой шаблон
<div class="tags">
{% for tag in all_tags %}
<div class="tag">
<p class="tag-title">{{ tag.name }}</p>
<input
type="checkbox"
class="checkbox-button"
name="checkboxes"
value="{{ tag.name }}"
/>
<p class="description">{{ tag.description }}</p>
</div>
{% endfor %}
</div>