In short, I'm having problems getting the drop-down value for a field in a 
child-of-a-child record; I want that value to be a field from the 
grandparent.

In more detail:

   1. I have three 'independent' tables ('independent' in that they have no 
   parents). Let's call them I1, I2, and I3.
   2. I have a child table that links I1 and I2 in a many-many 
   relationship. Let's call that table C1_2.
   3. I have a child table that links I3 and C1_2 in a many-to-many. Let's 
   call that table C1_2_3.
   4. When I add a C1_2_3 record, I'd like the values in the drop-down for 
   the C1_2 field to be taken from two of its parents' fields: I1.Name and 
   I2.I2.

Here's the table definitions:

db.define_table('I1',
                Field('Name', 'string', length=60, required=True),
                format='%(Name)s')

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

db.define_table('C1_2',
                Field('I1', db.I1),
                Field('I2', db.I2),
                Field('Start_date', 'date', required=True),
                format=lambda r: '%s %s' % (db.I1[r.I1].Name, 
db.I2[r.I2].I2))
db.C1_2.Start_date.requires = \
                [IS_DATE(),
                 IS_NOT_IN_DB(
                   db((db.C1_2.I1==request.vars.I1) &\
                      (db.C1_2.I2==request.vars.I2)),
                   'C1_2.Start_date')]

db.define_table('I3',
                Field('I3_name', 'string', required=True, unique=True),
                format='%(I3_name)s')

db.define_table('C1_2_3',
                Field('C1_2', db.C1_2),
                Field('C3', db.I3))
db.C1_2_3.C1_2.requires=IS_IN_DB(db, 'C1_2.id',
   lambda r: '%s' % (db.I1[db.C1_2[r.C1_2].I1].Name),
   _and=IS_NOT_IN_DB(db(db.C1_2_3.C1_2==request.vars.C1_2), 'C1_2_3.C3'))

For simplicity, in this example the value I want to see for the dropdown 
for field C1_2_3.C1_2 is just I1.Name (not I1.name and I2.I2 as described 
above).

Without the highlighted line the dropdown shows only the C1_2 id values.

With the highlighted line I get the error, "<type 'exceptions.KeyError'> 
'C1_2'" on the lambda definition.

1. Am I even allowed to have a lambda function there?
2. In any case, how can I get the drop-down to show me I1.Name?

Reply via email to