0👍
✅
This worked in the end:
class SearchPreferenceForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(SearchPreferenceForm, self).__init__(*args, **kwargs)
self.fields['location'].empty_values.append('all')
self.fields['school_type'].empty_values.append('all')
1👍
Your model needs blank=True
as well and null=True
location = models.ForeignKey(Location, blank=True, null=True)
school_type = models.ForeignKey(SchoolType, blank=True, null=True)
This post talks about blank and null.
- [Answer]-Validate nested form in Django
- [Answer]-Django many-to-many return list of releated objects
- [Answer]-Django 1.5, media root issue
Source:stackexchange.com