私は次のクラスベースのビューを持っています.
/?id=145
何か案は ?
class CityList(ListView):
template_name = "profile/profile.html"
model = City
def render_to_response(self, context, **response_kwargs):
if self.request.is_ajax() and self.request.GET.get('query'):
query = self.request.GET.get('query')
city_filter = [{'name': i.name,
'id': i.id}
for i in City.objects.filter(
name__icontains=query)]
results = city_filter
return HttpResponse(json.dumps(results),
mimetype='application/json')
elif self.request.GET.get('id'):
query = self.request.GET.get('id')
if query:
return HttpResponse(json.dumps(list(self.object_list.filter(
id=query).values('name', 'id')
)), mimetype='application/json')