On Wed, 2009-08-05 at 13:09 -0700, drakkan wrote:
> The code is something like this
> 
> obj=DBModels.objects.filter(somefilter)
> results=[]
> for o in obj:
>   results.append({'field1':o.field1,'field2':o.field2})
> 
> return JsonResponse(results)
> 
> where JsonResponse is a class derived from HttpResponse that add a
> simplejson.dumps
> 
> I have a really large database and in some edge case I need to return
> a large number of results (about 150.000 when I get the error). I make
> only one query with select_related and I tried also with DEBUG=False
> but nothing changed only the detailed stack trace isn't printed,
> 
> thanks
> drakkan
> 
> 

Then don't build up a big list, use and consume:

def worker():
    yield '['
    first = True
    for o in DBModels.objects.filter(somefilter).iterator():
       if not first:
           yield ','
       else:
           first = False
       yield simplejson.dumps({'field1':o.field1,'field2':o.field2})
    yield ']'
return HttpResponse(worker(), mimetype='application/json')

PS - AJAX applications aren't nice and snappy when dealing with that
quantity of information...

Tom


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to