If you know that there will be always less then 20 categories (because
of request quota limit) code is simple. If it could be more, then you
need to implement some pageing tehnics.
What you need is something like this:
....
rez = {}
ctgs = []
i = 0
for ctg in Category.all()
i += 1
ctParent = {}
ct = {}
ct['name'] = ctg.name
ct['id'] = ctg.id # I am not sure if it is possible to have
attribute id because of name collision, but try and see...
ctParent[str(i)] = ct
ctgs.append(ctParent)
rez = { categories_num: str(i), categories: ctgs }
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(demjson.encode(rez))
P.S. Why are you using demjson if you have already simplejson in
django.utils. Also this is good memcache candidate.
On Dec 13, 11:09 pm, TCH <[email protected]> wrote:
> hi im new to google appengine and webapp framework
>
> i have a model
>
> class Category(db.model):
> name = db.StringProperty()
>
> i want to get all the entries in this model as json
> im using demjson
>
> i want it like this
>
> {
> categories_num: 15 (number of categories)
> categories: {
> 1: {
> name: "automobile";
> id : "13",
> }
>
> 2: {
> name: "another";
> id : "2",
> }
> }
>
> }
>
> how can i get this??
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" 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/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---