I have the following parent-child:

db.define_table('Institution',
                Field('Institution_name', 'string', length=60, 
required=True,
                   unique=True),
                format='%(Institution_name)s')

db.define_table('Team',
                Field('Institution', db.Institution),
                ...

I retrieve some records:

   meetTeams = db(db.Team.id == request.args(1)).select(
                  db.Team.Institution, db.Team.Sex,
                  db.Institution.Institution_name,
                  join = [db.Team.on(db.Team.id == 
db.Participant_team.Team),
                          db.Institution.on(db.Team.Institution == 
db.Institution.id)])

I pull out some data:
for team in meetTeams:
   message += "%s %d %s\n" % (team.Team.Sex,
         team.Team.Institution,
         team.Institution.Institution_name)

I return locals(), and I have no explicit view. When meetTeams is 
displayed, the field team.Team.Institution displays with the 
expected/defined 'format'. When 'message' is displayed, 
team.Team.Institution shows up as an int.

Three questions:

   1. What's the 'magic' going on that tells the display code for meetTeams 
   to use the 'format' expression (but not to use it when displaying 
   'message')? Does it realize it's a row, and the row knows how to display 
   using the format?
   2. Are the results of that 'format' expression stored in the row, 
   available to me to use? As you can see I can explicitly join with the 
   Institution to get the name. But if there's an easier way, then I'll do it.
   3. If I don't reference Team.Institution in the SELECT field list, will 
   that avoid the various other SELECTs that get done to 'translate' an 
   Institution.id to the corresponding name (according to 'format') when 
   meetTeams is displayed?

Thanks.

-- 



Reply via email to