2👍
✅
Apparently, I had to override the Choice widget and change its render method to display no options. Since choices argument is still provided, the validation error does not occur and I can freely use javascript to render institutes by the city selected.
2👍
I had the same issue, but overcomed it by setting widget.choices to []
class StudentForm(forms.ModelForm):
city = forms.ModelChoiceField(City)
institute = forms.ModelChoiceField(queryset=Institute.objects.all())
def __init__(self, *args, **kwargs):
super(StudentForm, self).__init__(*args, **kwargs)
self.fields['institute'].widget.choices = []
- [Django]-SQL query to filter on group of related rows
- [Django]-PostgreSql Integer out of range error when inserting small numbers into integer fields
- [Django]-"detail": "Authentication credentials were not provided." for general views
0👍
You should ensure that the Institute
values that get filled up in the select box should also have the primary key as the html id
attribute.
- [Django]-Updating foreign key field in Django
- [Django]-Increase the performance in Django ORM
- [Django]-How do I populate a ModelChoiceField from two Models
- [Django]-Django Celery Memory not release
Source:stackexchange.com