I am doing an attendance system and the student is able to mark their attendance by looking for their name in the dropdown list value. The student will then press submit and the information will be stored in MarkAtt database. Currently it did not display the students name accordingly to class, and when i click submit it display the following errors: "valueerror" showed up. ValueError Exception Value: Cannot assign ", , ......"MarkAtt.studName" must be a "Namelist" instance. I need the selected name of the students to be stored in the database per one click....
class MarkAtt(models.Model):
studName = models.ForeignKey(Namelist,on_delete=models.SET_NULL,blank=True, null=True, default=None)
classGrp = models.ForeignKey('GroupInfo', on_delete=models.SET_NULL, null=True)
currentDate = models.DateField(default=now())
week = models.IntegerField(default=0)
attendance = models.IntegerField(default=1) #1 is present
The Template displays the class information, today's date and the student's name in a drop drown list box.
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
Lab Group: {{group.classGrp}} //this is from another view
Day: {{group.day}}
Time: {{group.time}}
Today's date: {{today.date}}
{{form.as_p}}
The view:
def mark_stud(request,id):
group = GroupInfo.objects.get(id=id)
studName = Namelist.objects.filter(classGrp=id)
information = {}
information['group'] = group
information['studName'] =studName
if request.method == 'POST':
form = studentAttendanceForm(request.POST)
if form.is_valid():
att = form.save(commit=False)
att.studName = information['studName']
att.currentDate = datetime.datetime.now.date()
form.save()
return redirect('namelist.html')
else:
form = studentAttendanceForm()
return render(request, 'namelist.html', {'information' :information, 'form':form})
Forms.py
class studentAttendanceForm(forms.ModelForm): class Meta: model = MarkAtt fields = ['studName'] label = { 'name': 'Student Name' }
def __init__(self,*args, **kwargs):
super(studentAttendanceForm, self).__init__(*args,**kwargs)
self.fields['studName'].label = "Select your name:"
However, the form did not display in the template page and i am unable to save the value in the database. Really appreciate your help. Thank you so much.