web2py includes a json field type, which automatically converts to and from
JSON, so you can just do:
Field('list1a', 'json')
Then just insert the Python object directly, and it will be converted to
JSON on insert and converted back to Python when selected.
More generally, for other types of specialized data structures, look into
filter_in/filter_out<http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#filter_in-and-filter_out>
(note,
the JSON example was created before the new json field type was
introduced) and
SQLCustomType<http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Custom-Field-types-(experimental)>
.
Anthony
On Saturday, November 16, 2013 3:54:24 AM UTC-5, Sarbjit wrote:
>
> I am using the slice from
> http://www.web2pyslices.com/slice/show/1721/google-charts-plugin.
>
> To store the data to be used for plotting in google charts, I am using the
> following :
>
> To Create :- (Example)
>
> data = [['Year','Sales','Expenses'],["2004",1000,400],["2005",1100,440]]
>
> How I am doing :-
>
> list1 = [] # For Row2 (how to store and retrieve from db)
> list1.append("2004")
> list1.append(1000)
> list1.append(400)
>
> import json
> list1b = json.dumps(list1)
> db.sampletable.insert(list1a=list1b)
> db.commit()
>
> >>>>>>
> x = db(db.sampletable.id==1).select()[0].list1a
> json.load(x)
> AttributeError: 'str' object has no attribute 'read'
>
> Similarly, If I don't use the json.dumps method first, I get the same
> error.
>
> I want to know how can I store the sublists in db and then can retrieve
> them to make them as data list (pointed in the beginning).
>
> -Sarbjit
>
>
--
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/groups/opt_out.