>
> *tip: '{{db.executesql('SELECT first_name, last_name FROM tech WHERE id = 
> 'row.tech';')}}',*


There are several things wrong with the above. First, you're getting a 
syntax error because you've got 'row.tech' in single quotes inside a string 
that is also in single quotes. Second, the SQL string is just a string that 
gets passed to the database, so it cannot contain Python variables like 
"row.tech". Finally, if you want to write something into a template inside 
the {{...}} delimiters, you need to use "=" (i.e., {{=db.executesql(...)}}). 
Anyway, there's no reason to use executesql() here -- this does the same 
thing as the DAL select.

Also, why does the db.tech table include first_name and last_name columns 
-- aren't those redundant with the same columns in db.auth_user?

Anyway, since row.tech is the id in the db.tech table, you can use it to 
select the record from that table and fill in a string with the fields you 
want:

  tip: '{{='%(first_name)s %(last_name)s' % db.tech(row.tech)}}'

However, that will do an additional select for each tech, which is 
inefficient if you have a long list. Instead, you might consider making 
your initial query a join and include the name fields in the main rows 
object:

def mycal():
    rows=db((db.work_order.tech==auth.user.id) & (db.work_order.tech==db.
tech.id))\
         .select(db.work_order.ALL, db.tech.first_name, db.tech.last_name)

and in the view:

  tip: '{{='%(first_name)s %(last_name)s' % row.as_dict()['tech']}}'

Anthony

-- 

--- 
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.


Reply via email to