from django.http import HttpResponse from django.shortcuts import render_to_response from objects.models import * import simplejson def index(request): objsearchform = ObjectSearchForm(auto_id="catalogsearch") return render_to_response("objects/index.html", {"catalogsearch": objsearchform, "user": request.user}) def ean_lookup(request): query = request.GET["q"].split(",") try: results = Product.objects.filter(code__in=query) products = [] for r in results: products.append({ 'code': r.code, 'name': r.name }) return HttpResponse(simplejson.encode(products)) except Exception as e: print e return HttpResponse("[]")