Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove specific form field from validating (is_valid) django

There are four field in django form and i am using is_valid() function to validate, but instead of validating the whole form i want to exclude one field which should not be validate using is_valid() function

like image 497
Cipher Avatar asked Dec 01 '25 13:12

Cipher


1 Answers

You can use exclude parameter inside your form to exclude the fields you don't want to get validated.

Let's say you have a model named MyModel and a model form for it named MyForm

# forms.py

from django import forms
from .models import MyModel

class MyForm(forms.ModelForm):
    class Meta:
        model = MyModel 
        exclude = ['field_name_you_want_to_exclude']
like image 85
Vipin Gupta Avatar answered Dec 04 '25 06:12

Vipin Gupta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!