# Check form errors if is\_valid() method is False

**URL:** <https://forum.djangoproject.com/t/check-form-errors-if-is-valid-method-is-false/25787>\
**Category:** Forms & APIs\
**Created:** [November 30, 2023, 1:05pm UTC](https://forum.djangoproject.com/t/check-form-errors-if-is-valid-method-is-false/25787 "2023-11-30T13:05:16Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 5, 2023, 10:36pm UTC](https://forum.djangoproject.com/t/check-form-errors-if-is-valid-method-is-false/25787/22 "2023-12-05T22:36:43Z")

</div>

> [@mfreitas64](#):
>
> ```auto
> instance = getattr(self, 'instance', None)
> if instance and instance.id:
> self.fields['regalunoid'].required = False
> self.fields['regalunoid'].widget.attrs['disabled'] = 'disabled'
> 
> ```

This is entirely unnecessary when using:

> [@mfreitas64](#):
>
> ```auto
> 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](#):
>
> ```auto
> 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.)

---

<div class="post-metadata">

**Author:** ![mfreitas64](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mfreitas64/32/10995_2.png) [@mfreitas64](https://forum.djangoproject.com/u/mfreitas64)\
**Post date:** [December 6, 2023, 12:29pm UTC](https://forum.djangoproject.com/t/check-form-errors-if-is-valid-method-is-false/25787/23 "2023-12-06T12:29:01Z")

</div>

I’ve tried that but it doesn’t work

---

<div class="post-metadata">

**Author:** ![mfreitas64](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mfreitas64/32/10995_2.png) [@mfreitas64](https://forum.djangoproject.com/u/mfreitas64)\
**Post date:** [December 6, 2023, 2:58pm UTC](https://forum.djangoproject.com/t/check-form-errors-if-is-valid-method-is-false/25787/24 "2023-12-06T14:58:28Z")

</div>

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:

 ![Screenshot 2023-12-06 at 14.46.17](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/8/3/83bcb4a62c39cf935039b7af582d71ebaf41e816.png)

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?

[Previous page](https://forum.djangoproject.com/t/check-form-errors-if-is-valid-method-is-false/25787.md?page=1)
