Django poll - change from only one seleted option (radio) in multiple selection (checkbox) and register all togheter

I made a poll app in django. It work ok but what i want to change is the selection an register vote option. Now i can select and register one option ('participanti') (radio btn select) and i want to be able to let the user to select more than one "participanti" (1 or 1 to maximum 3 ) in the same instance and after submit to register all the option/participanti selected (1 or 2 or all maximum 3 that user selected) . I don't know how to approach this kind of mechanism. Please help me with a solution. Thank you very much. Below mai settings

models

class Campanie(models.Model):
.....

class Participanti(models.Model):
    campanievot = models.ForeignKey(Campanie, on_delete=models.CASCADE)
    nume_participant = models.CharField(max_length=200, verbose_name='nume')
    dep_participant = models.CharField(max_length=200, verbose_name='departament')
    votes = models.IntegerField(default=0)
    def __str__(self):
        return self.nume_participant

    class Meta:
        verbose_name = 'Participanti'
        verbose_name_plural = 'Participanti'

views.py

def votare_campanie(request):

    campanie = get_object_or_404(Campanie)
 
    try:
        participant_votat = campanie.participanti_set.get(pk=request.POST['participanti'])
       

    except (KeyError, Participanti.DoesNotExist):
      
        return render(request, 'campanievot/campanie.html', {
            'campanie' : campanie,
            'error_message' : "Trebuie sa votezi cel putin un coleg",
        })
    else:
        participant_votat.votes += 1
        participant_votat.save()
 
        messages.success(request, "Multumim pentru feedback!")
        return redirect('campanievot:index')

template.html

<form action=" {% url 'campanievot:votare_campanie'%} " method="post" >
                {% csrf_token %}

                {% for p in campanie.participanti_set.all %}

                {% if p.dep_participant == request.user.departament %}

                {% else %}

               <label for="p{{ forloop.counter }}" class="form-check custom-icon mt-2 mb-4" role="button">
                    <input type="radio" name="participanti" class="form-check-input" id="p{{ forloop.counter }}"
                        value="{{ p.id }}">
                    <span class="form-check-label">
                        <span class="content">
                            <span for="p{{ forloop.counter }}" class="heading mb-1 d-block lh-1-25">{{p.nume_participant }} {{ p.dep_participant }}</span>
                            <!-- <span class="d-block text-small text-muted">04.05.2021 - 12:00 </span> -->
                        </span>
                    </span>
                </label>

                {% endif %}

                {% endfor %}
                {{form.media}}
            
                <button class="m-auto btn btn-icon btn-icon-start btn-primary mb-1" type="submit">
                    <i data-acorn-icon="send"></i>
                    <span>Trimite</span>
                </button>
            </form>

Thank you!

Back to Top