web2py Shell 2.9.5-stable+timestamp.2014.03.16.02.35.39
In [1] : tos = db(db.auth_criteria.toSend ==1).select()
In [2] : tos
<Rows (1)>
In [3] : for row in tos:
print row.user_id.email
Traceback (most recent call last):
File "/Users/LaViez/Documents/Python/web2py/gluon/contrib/shell.py", line 234, in run
exec compiled in statement_module.__dict__
File "<string>", line 2, in <module>
AttributeError: 'long' object has no attribute 'email'db.define_table('auth_criteria',
Field('user_id', 'reference auth_user',requires = IS_IN_DB(db, 'auth_user.id'), readable=False, writable=False),
Field('salePrice', 'integer', widget=SQLFORM.widgets.radio.widget, requires = IS_IN_SET(salePrice)),
Field('toSend','integer', readable=False, writable=False))
db.auth_criteria.id.readable=False db.post.image_id.requires = IS_IN_DB(db, db.image.id, '%(title)s')
db.thing.owner_id.requires = IS_IN_DB(db,'person.uuid','%(name)s')
if request.args(0)=='profile':
db.auth_criteria.user_id.default = auth.user.id
record = db.auth_criteria(db.auth_criteria.user_id.default)
formFil=SQLFORM(db.auth_criteria,
record=record,
labels = {'salePrice':XML('By Sale Price')},
buttons = [TAG.button('Set Mine', _class='btn-primary')])web2py Shell 2.9.5-stable+timestamp.2014.03.16.02.35.39
In [1] : tos = db(db.auth_criteria.toSend ==1).select()
In [2] : tos
<Rows (1)>
In [3] : for row in tos:
print row.user_id.email
Traceback (most recent call last):
File "/Users/LaViez/Documents/Python/web2py/gluon/contrib/shell.py", line 234, in run
exec compiled in statement_module.__dict__
File "<string>", line 2, in <module>
AttributeError: 'long' object has no attribute 'email'
db(db.auth_criteria.toSend ==1).select().first().user_id.emailBtw, I find some inconsistency in the book 6th edition.
In the Overview section:db.post.image_id.requires = IS_IN_DB(db, db.image.id, '%(title)s')
But in DAL section:db.thing.owner_id.requires = IS_IN_DB(db,'person.uuid','%(name)s')
I hope this -M option could be documented better in the book. Now I have my friend iPython with me.In [5]: rowtosend = db(db.auth_criteria.toSend==1).select()
In [7]: rowtosend
Out[7]: <Rows (1)>
In [8]: for row in rowtosend:
...: print row.user_id.email
...:
xxxxxx@gmail.commyList = []
for row in rowsToSend:
email = row.user_id.email
myList = myList.append(email)
myList.append(email)
Well, thanks everyone. I learned how to use iPython with web2py today. It will help me a lot in future develpment.
rowstosend = db(db.auth_criteria.toSend == 1).select()
mylist = [row.user_id for row in rowstosend]
mylist = [row.user_id.email for row in rowstosend]
rowstosend = db((db.auth_criteria.toSend == 1) &
(db.auth_criteria.user_id == db.auth_user.id)).select()
mylist = [row.auth_user.email for row in rowstosend]
rowstosend = db((db.auth_criteria.toSend == 1) &
(db.auth_criteria.user_id == db.auth_user.id)).select(db.auth_user.email)
import pandas as pd
def pandas_df(rows, fields, columns, cacheable):
return pd.DataFrame.from_records(rows, columns=columns)
df = db((db.auth_criteria.toSend == 1) &
(db.auth_criteria.user_id == db.auth_user.id)).select(processor=pandas_df)
mylist = df['email'] # now you have a Pandas Series