Django - How to make an optional field required based on request
By : user3862140
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Solved my problem by subclassing my forms as follows : My form based on my model with null and blank = True code :
class RegionForm(forms.ModelForm):
class Meta:
model = Region
fields = ['region_name',
'region_description'
]
def __init__(self, *args, **kwargs):
super(RegionForm, self).__init__(*args, **kwargs)
for field in self.fields:
self.fields[field].required = True
class RegionDraftForm(RegionForm):
class Meta(RegionForm.Meta):
pass
def __init__(self, *args, **kwargs):
super(RegionDraftForm, self).__init__(*args, **kwargs)
for field in self.fields:
self.fields[field].required = False
|
Django: Email field in form returning 'this field cannot be null/this field cannot be blank' even though there's an addr
By : Ahmed Mohsen
Date : March 29 2020, 07:55 AM
|
Correct way to set optional Django field to blank?
By : Cloud
Date : March 29 2020, 07:55 AM
seems to work fine You may pass None as the field value because your field has the attribute null set to True. So you can have: code :
club = Club.objects.create(hostname=form.cleaned_data['hostname'], co_hostname=None)
|
Retrieving Django QuerySet matching field in reverse query (related_name)
By : user2442005
Date : March 29 2020, 07:55 AM
|
A required field in form must now be made optional with a new field becoming required while having an optional relations
By : shridharbee
Date : October 06 2020, 11:00 AM
|