Помогите преобразовать код. Мне необходимо, чтобы программа могла записывать в бд более 1 выбора пользователя. Т.е преобразовать radio в checkbox. Если просто заменить одно на другое, то все еще сохраняется только 1 ответ (причем последний выбранный)
html
<div class="container">
<h1>Polls details page</h1>
{% if messages %}
<div class="messages">
{% for message in messages %}
<div {% if message.tags %} class="{{ message.tags }}" {% endif %}>{{ message }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
{% endfor %}
</div>
{% endif %}
<hr>
<h2 class="mt-3 mb-3">{{ poll }}</h2>
<form action="{% url 'polls:vote' poll.id %}" method="POST">
{% csrf_token %}
{% for choice in poll.choice_set.all %}
<input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}">
<label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label>
<br>
{% endfor %}
<input type="submit" value="Vote" class="btn btn-primary mt-3">
<a class="btn btn-warning mt-3" href="{% url 'polls:list' %}" role="button">Cancel</a>
</form>
</div>
views
def poll_vote(request, poll_id):
poll = get_object_or_404(Poll, pk=poll_id)
choice_id = request.POST.get('choice')
if not poll.user_can_vote(request.user):
messages.error(
request, "You already voted this poll", extra_tags='alert alert-warning alert-dismissible fade show')
return redirect("polls:list")
if choice_id:
choice = Choice.objects.get(id=choice_id)
vote = Vote(user=request.user, poll=poll, choice=choice)
vote.save()
print(vote)
return render(request, 'polls/poll_result.html', {'poll': poll})
else:
messages.error(
request, "No choice selected", extra_tags='alert alert-warning alert-dismissible fade show')
return redirect("polls:detail", poll_id)
return render(request, 'polls/poll_result.html', {'poll': poll})