Re: Is it possible to output JSON like this?

2008-11-07 Thread Dj Gilcrease
On Fri, Nov 7, 2008 at 12:17 AM, Darthmahon <[EMAIL PROTECTED]> wrote: > > Hi guys, I'll give both a try tomorrow when I am near my dev box > again. Can't really do it in the template as I just want to dump out > JSON only, but I'll give them both a go :) I use templates for all my JSON output,

Re: Is it possible to output JSON like this?

2008-11-06 Thread Darthmahon
Hi guys, I'll give both a try tomorrow when I am near my dev box again. Can't really do it in the template as I just want to dump out JSON only, but I'll give them both a go :) Cheers, Chris On Nov 6, 9:51 am, "Dj Gilcrease" <[EMAIL PROTECTED]> wrote: > If you dont mind using the template

Re: Is it possible to output JSON like this?

2008-11-06 Thread Dj Gilcrease
If you dont mind using the template system I think this should produce the results you are looking for [{% for event in events %} {% ifchanged event.date %}{ 'date' : '{{ event.date }}', 'dayEvents' : [{% endif %} { 'title' : '{{ event.title }}', 'location' : '{{

Re: Is it possible to output JSON like this?

2008-11-06 Thread Alex Koshelev
It's strange. I've just try this example and it is good: In [1]: results = [] In [2]: results.append( { 'date' : '2008-11-04 00:00:00', 'dayEvents' : ...: [ { 'title' : 'Event 1', 'location' : '1', 'id' : '1' }, { 'title' : ...: 'Event 2', 'location' : '1', 'id' : '2' } ] } )

Re: Is it possible to output JSON like this?

2008-11-06 Thread Darthmahon
Hey Alex, I tried this hard coded JSON the other day: results = [] results.append( { 'date' : '2008-11-04 00:00:00', 'dayEvents' : [ { 'title' : 'Event 1', 'location' : '1', 'id' : '1' }, { 'title' : 'Event 2', 'location' : '1', 'id' : '2' } ] } ) But I got an error when I did this (can't

Re: Is it possible to output JSON like this?

2008-11-05 Thread Alex Koshelev
With simplejson module (that is part of django distribution) you can covert to JSON any python objects. So create data structure you need and pass it to simplejson dump/dumps functions. On Thu, Nov 6, 2008 at 01:17, Darthmahon <[EMAIL PROTECTED]> wrote: > > Hi, > > Ok I'm using the following

Is it possible to output JSON like this?

2008-11-05 Thread Darthmahon
Hi, Ok I'm using the following code to turn my model into JSON: from django.core import serializers json = serializers.serialize("json", Event.objects.all()[:5], fields=('title','date','location')) Now, this returns JSON like this: [ { "pk": 1, "model": "events.event", "fields": {