You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
802 B
25 lines
802 B
import json
|
|
from django.views.generic import DetailView
|
|
from django.http import HttpResponse
|
|
from models import City
|
|
|
|
|
|
class CityView(DetailView):
|
|
model = City
|
|
slug_field = 'url'
|
|
template_name = 'city/city.html'
|
|
|
|
|
|
def get_city(request):
|
|
if request.is_ajax():
|
|
country = request.GET['country']
|
|
term = request.GET['term'].capitalize()
|
|
if not term:
|
|
qs = City.objects.language().filter(country=country).order_by('translations__name')[:100]
|
|
else:
|
|
qs = City.objects.language().filter(country=country, translations__name__contains=term)
|
|
result = [{'id': city.id, 'label': city.name} for city in qs]
|
|
|
|
return HttpResponse(json.dumps(result), content_type='application/json')
|
|
else:
|
|
return HttpResponse('not ajax') |