Update: this works however if I don't delete the _extra field, but then 
newName is not available!
Le lundi 12 novembre 2012 09:24:12 UTC+1, dederocks a écrit :
>
> NB : however, the standard function doesn' work anymore (e.g. without the 
> '.json' extension). I get a invalid function (default/handle_error). Why?
> Le lundi 12 novembre 2012 09:19:50 UTC+1, dederocks a écrit :
>>
>> This is great, thank you! And I don't know why but this is great too, the 
>> update applies *directly* to the data object (I therefore don't have to 
>> create a new one).
>>
>> Le jeudi 8 novembre 2012 19:27:29 UTC+1, Massimo Di Pierro a écrit :
>>>
>>> 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
>>>>
>>>

-- 



Reply via email to