This is my List in the HTML document
I have a Django post view, when I hit send I want the selected users to be posted to the students field.
As you can see I have tried to do the instance and user thing from this url but I can't figure it out!
HTML:
{% for elev in elever %}
<div class="custom-control custom-checkbox">
<span class="d-flex align-items-center">
<div style="margin-right: 10px">
<div class="circle" style="background-color: {{ elev.color }}">
<span class="initials" , style="color: #ffffff"> {{ elev.user|capfirst|first }}
</span>
</div>
</div>
<div style="width: 300px">
<span class="h6 mb-0" data-filter-by="text">{{elev.user|capfirst}}</span>
</div>
<div class="checkboxx"> <input type="checkbox" name="Studyplan-Canview" value= "{{ student.name }}">
<style>
.checkerName {
margin-left: 10px
}
.checkboxx {
align-content: flex-end;
margin-left: 300px
}
</style> </div>
</span>
</label>
</div>
{% endfor %}
The View:
#post request checker
@login_required
def skapa_studieplan(request):
if request.method == 'POST':
name = request.POST.get('Studyplan-Name')
description = request.POST.get('Studyplan-Description')
parent_assignment = Assignment.objects.get(pk=request.POST.get('Studyplan-PAID'))
users = UserProfile.objects.all()
instance = Studyplan.objects.create(request.POST.get('Studyplan-Canview'))
for user in users:
instance.canview.add(user)
studyplan = Studyplan(name=name, description=description, parent_assignment=parent_assignment, canview=instance)
studyplan.save()
return redirect('allaStudieplaner')