I have something like this in my template.
<form action="" method="POST">
{% csrf_token %}
<select name='section'>
{% for item in all_sections %}
<option>{{ item.SectionName }}</option>
{% endfor %}
</select>
</form>
and in my view.py page:
obj=models.Section.objects.all()
context={
'all_sections':obj,
}
return render(request,'matab/add-service.html',context)
but i get this is error while saving data:
Cannot assign "'{item}'": "Services.Section" must be a "Section" instance.
also my models.py is like this:
class Section(models.Model):
SectionName=models.CharField(max_length=50)
SectionId=models.CharField(max_length=10)
class Services(models.Model):
Section=models.OneToOneField(
Section,
on_delete=models.CASCADE,
)
how can i solve it?
<option value="{{ item.id }}">