Hi everyone,
I'm a web2py newbie and I'm having some hard time with the following simple task:
I would like to show in a page all the records stored in the following MongoDB document (called requests):
{
"request": {
"slice": [
{
"origin": "SFO",
"destination": "MIA",
"date": "2014-08-21"
}
]
}
}
My approach would be define a table with a json field and then parse it:
db.py:
db.define_table('requests',
Field('request','json'))
default.py:
def all_records():
grid = SQLFORM.grid(db.requests, fields=[db.requests.request.slice[0].origin,db.requests.request.slice[0].destination,db.requests.request.slice[0].date)
return locals()
all_records.html:
{{extend 'layout.html'}}
{{=BEAUTIFY(response._vars)}}
Though, I get this error:
<type 'exceptions.AttributeError'> 'Field' object has no attribute 'slice'
so I guess I'm parsing the JSON file in the wrong way.
Any help is more than welcome,
thanks