-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
django-select2 whit django-cities loops. #41
Comments
I don't use Auto*Field, but django-cities works nice in my app (you can try in on search form on http://www.4job.co). forms.py class SearchFormSimple(forms.Form):
loc = HeavySelect2MultipleChoiceField(
widget=HeavySelect2MultipleWidget(
data_view='cities_json',
select2_options={
'placeholder': _('Type city name')
}
),
required=False) urls.py ...
url(r'^select2/cities/', CitiesSelect2View.as_view(),
name='cities_json'),
... views.py class CitiesSelect2View(Select2View):
""" Data view for Cities """
max_results = 15 # page size is max_results
def get_results(self, request, term, page, context):
from cities.models import City
curr_lang = get_language()[0:2]
if curr_lang == 'ru':
city_set = (City.objects
.filter(alt_names_ru__name__istartswith=term)
.distinct()
.order_by('name'))
else:
city_set = (City.objects
.filter(name__istartswith=term)
.distinct()
.order_by('name'))
min_ = (page - 1) * self.max_results
max_ = min_ + self.max_results + 1
city_set = list(city_set[min_:max_])
has_more = len(city_set) == (max_ - min_)
if has_more:
city_set = city_set[:-1]
res = []
from .utils import full_city_rec
for city in city_set:
names = full_city_rec(city, curr_lang)
res.append((city.id, ", ".join(names)))
return (NO_ERR_RESP, has_more, res) hope this helps you. |
Thanks that helps.. Currently I am swamped by other tasks and my job of course, so you can except delay in my response. |
Well the code uses normal Django code for the validation. So if the submitted value is stored in |
Ok now I understand the real issue. When django-select2 widgets render they loop through all the rows and discard them. This has been fixed in v4.2.1. |
Hi
Can't get django-select2 play nice whit django-cities any one have a suggestion?
The problem is that on validation of a submitted from django-select2 loops the entier db off django-cities (22K+ rows) it takes a long time.
form.py
views.py
The text was updated successfully, but these errors were encountered: