You can try this. Yet I found some problem as data.json() does not behave
well as json(data) while they should be the same.
from gluon.serializers import json
db =DAL()
db.define_table('test',Field('name'),Field('firstname'))
db.test.insert(name='Test',firstname='Test')
count = db.test.id.count()
data = db().select(db.test.ALL,
count,
groupby=db.test.id,
orderby=db.test.name)
for row in data:
row.test.newName = row(count)
del row._extra
print row
print json(data)
On Thursday, 8 November 2012 11:24:14 UTC-6, dederocks wrote:
>
> Hello,
>
> If I define a table with
> define_table('test',Field('name'),Field('firstname'))
>
> Then in the controller, I have:
> count = db.test.id.count()
> data = db().select(db.test.ALL,
> count.with_alias('newName'),
> groupby=db.test.id,
> orderby=db.test.name)
>
> In the view displaying data as json (view.jason) I get:
>
> {"data": [{"test": {"name": "UserName", "firstname": "FirstName"},
> "newName": 1, "_extra": {"COUNT(test.id) AS newName": 1}}, ...
>
> Which I thought was not correct, but Massimo said this is the intended
> behaviour as 'count' does not belong necessarily to a table.
>
> So can someone help me and give me a hint on how I could format the json
> output like:
>
> {"data": [{"test": {"name": "UserName", "firstname": "FirstName",
> "newName": 1}, ... ?
>
> Thanks in advance for your feedback!
> Andre
>
--