itf/itf/itfprofiles/views.py
2012-06-23 02:13:39 +05:30

25 lines
965 B
Python

# Create your views here.
from models import *
from forms import *
from django.shortcuts import render_to_response
from ox.django.shortcuts import render_to_json_response
from django.core.paginator import Paginator, InvalidPage, EmptyPage
def person_form(request):
return render_to_response("test/person_form.html", {'form': PersonForm})
def autocomplete(request):
q = request.GET.get('q', 'a')
page = int(request.GET.get('page', '1'))
page_limit = int(request.GET.get('page_limit', '10'))
#qset_all = Person.objects.all()
qset = Person.objects.filter(first_name__icontains=q)
paginator = Paginator(qset, page_limit)
results = paginator.page(page)
items = [{'id': obj.id, 'first_name': obj.first_name, 'last_name': obj.last_name, 'text': obj.first_name} for obj in results.object_list]
return render_to_json_response({
'items': items,
'has_next': results.has_next()
})