I cannot seem to figure this, although I suspects it is really elementary:
I have two models:
class Employee(models.Model):
id_number = models.CharField(max_length=13)
surname = models.CharField(max_length=100)
name = models.CharField(max_length=100)
class Payslip(models.Model):
surname = models.CharField(max_length=100)
name = models.CharField(max_length=100)
salary = models.DecimalField(max_digits=20, decimal_places=2)
In my forms:
class PayslipForm(ModelForm):
class Meta:
model = Payslip
fields = ['surname', 'name', 'salary']
PayslipFormSet = modelformset_factory(Payslip, extra=0)
In views.py:
def Payslip(request):
employee = Employee.objects.all()
formset = PayslipFormSet(queryset=employee)
context = {'formset': formset}
return render(request, 'file.html', context)
def PayslipSubmit(request):
f = PayslipFormSet(request.POST)
if f.is_valid():
f.save()
return HttpResponse('Submitted')
else:
return HttpResponse(f.errors)
The problem is that when I submit I get the following each form in formset:
- id
- Select a valid choice. That choice is not one of the available choices.
I hope someone can help!