You will need to export the list of objects to the JSON dictionary.
if request.path == "/sort/":
sortid = request.POST.get('sortid')
locs = Location.objects.order_by(sortid)
if request.is_ajax():
import json
return HttpResponse(json.dumps(locs), mimetype="application/json")
However, you will need to use some client-side template system.
Django render_to_response. JSON. .
, AJAX. - , HTML, AJAX. - , , .
, my object_list.html:
<ul id='object-list'>
{% for object in object_list %}
<li>{{ object.value }}</li>
{% endfor %}
</ul>
base.html:
<html>
<title>Example</title>
<body>
{% include 'object_list.html' %}
</body>
</html>
:
from django.shortcuts import render_to_response
from django.template import RequestContext
from models import Location
def view(request):
locs = Location.objects.order_by(sortid)
if request.is_ajax():
return render_to_response('object_list.html', {'object_list': locs}, context_instance=RequestContext(request))
return render_to_response('base.html', {'object_list': locs}, context_instance=RequestContext(request))
GET XHTTP, HTML, . Handy!