-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Description
Some people may encounter the error of 'NoneType' object has no attribute 'city_set' if you implement this to a profile system or any other similar model. My way around to fix it was :
if 'country' in self.data:
try:
country_id = int(self.data.get('country'))
self.fields['city'].queryset = City.objects.filter(country_id=country_id).order_by('name')
except (ValueError, TypeError):
pass # invalid input from the client; ignore and fallback to empty City queryset
elif self.instance.pk:
try:
self.fields['city'].queryset = self.instance.country.city_set.order_by('name')
else:
pass
Metadata
Metadata
Assignees
Labels
No labels