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
<https://nicolabarbieri.pythonanywhere.com/examples/global/vars/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
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.