im using django select2 for a chained single model select in register webpage. as i know django select2 expose an ajax endpoint that make all that is needed to search, paginate and select my cities. there is a way i can use this service that django-select2 creates automatic for using it in my app?
city = forms.ModelChoiceField(
queryset=City.objects.all(),
label=u"City",
widget=ModelSelect2Widget(
model=City,
search_fields=['name__icontains'],
dependent_fields={'country': 'state__country'},
max_results=20,
attrs={'class': 'form-control','width': '100%',},
)
)
this is my city widget, and i have a a custom widget that did to test if i can expose it to everyone
class TitleSearchFieldMixin(object):
search_fields = [
'name__icontains',
'pk__startswith'
]
class CitySelect2TagWidget(TitleSearchFieldMixin, ModelSelect2Widget):
model = City
def get_queryset(self):
return self.model.objects.filter()
def label_from_instance(self, obj):
return force_text(obj.name).upper()
class CountrySelect2TagWidget(TitleSearchFieldMixin, ModelSelect2Widget):
model = Country
dependent_fields = {'country': 'country'}
def get_queryset(self):
return self.model.objects.filter()
def label_from_instance(self, obj):
return force_text(obj.name).upper()
thanks a lot for your answers