This is entirely unnecessary when using:
mfreitas64:
regalunoid = forms.ModelChoiceField(
queryset=Alunos.objects.all(),
label="Aluno:",
required=False,
widget=forms.Select(attrs={'disabled': 'disabled'}))
(It’s doing the same work twice.)
and this is also unnecessary with a disabled/non-required field:
mfreitas64:
def clean_regalunoid(self):
instance = getattr(self, 'instance', None)
if instance:
return instance.regalunoid
else:
return self.cleaned_data.get('regalunoid', None)
(It’s not that it’s “wrong”, it’s just an extra 10 lines of code between the two places that you don’t need.)
I’ve tried that but it doesn’t work
So, now everything is working but it’s not doing what I need. The form only updates the records that are already created in the Registers class but I need the form to also create the records on the Registers class if they don’t exist for the selected date.
Here is the form has it looks now:
So, if I select a Lesson date and Submit the form the records on the Registers class are updated with the new selected date.
But what I need/want is to create a new set of records on the Registers class every time the selected Lesson date is different.
How can I do that?