Hi,
I’m having problems with the is_valid() method :
I have this form
from django import forms
from .models import Registers, Alunos
class RegisterForm(forms.ModelForm):
regalunoid = forms.ModelChoiceField(queryset=Alunos.objects.all(), label="Aluno:",
widget=forms.Select(attrs={'disabled': 'disabled'}))
lesson_at = forms.DateField(widget=forms.DateInput(attrs={"type": "date"}))
class Meta:
model = Registers
fields = ["lesson_at", "regalunoid", "status"]
labels = ["Data", "Aluno", "State"]
exclude = ["regclasseid"]
This is the view
def RegisterUpdate(request, **kwargs):
t = Turmas.objects.get(id=kwargs['pk'])
RegisterFormSet = modelformset_factory(Registers, form=RegisterForm, extra=0)
form = RegisterFormSet(queryset=Registers.objects.filter(regclasseid=kwargs['pk']))
if request.method == 'POST':
for name in request.POST:
print("{}: {}".format(name, request.POST.getlist(name)))
if form.is_valid():
form = RegisterFormSet(request.POST)
form.save()
return render(request, 'schooladmin/turmas.html')
else:
print("failed to validate form")
return render(request, 'schooladmin/registers.html', {'form': form, 'turma': t})
After the Submit I get this output on the server console:
csrfmiddlewaretoken: ['CxNje0WqOWpsnCgmfXsgKoJmJM2CZ71L7rel4qAJTr5cPCpJDOwU2dRbQbWPSSBs']
form-TOTAL_FORMS: ['3']
form-INITIAL_FORMS: ['3']
form-MIN_NUM_FORMS: ['0']
form-MAX_NUM_FORMS: ['1000']
form-0-lesson_at: ['2023-11-28']
form-0-status: ['P']
form-0-id: ['1']
form-1-lesson_at: ['2023-11-28']
form-1-status: ['P']
form-1-id: ['2']
form-2-lesson_at: ['2023-11-28']
form-2-status: ['P']
form-2-id: ['3']
**failed to validate form**
So I can conclude that the instruction
if form.is:valid()
is not True.
Where and how can I check the form errors or how can I fix this?
Thank in advance