I've a function findParent
that takes a string, compares it with something else in db
and returns another string. I wrote this in a .py file.
products=db(findParent(db.product_info.source_place)==auth.user.place).select()
The problem is, db.product_info.source_place
doesn't etract source_place
from db
but instead sends the string itself ie findParent
recieves db.product_info.source_place
but not the corresponding value from the db
.
What am I doing wrong?
When you are comparing two fields in case like:
products=db(table1.field1==table2.field2).select()
It return a table after applying the join on these two fields. When you use findParent(db.product_info.source_place)
, the findParent
is just considering as string db.product_info.source_place
because it is not actually called for all the rows in the tables and called once and evaluated and then all rows of the auth.user
are compared with that return value for the place column.
Solution added:
rows=db(db.product_info).select(db.product_info.source_place) listwantedsource=[] for row in rows: listwantedsource.append(findParent(row.source_place)) products=db(auth.user.place.belongs(listwantedsource)).select()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.