1

I have three fields that must be unique in a table, and based on the answer to this question I attempted the following (I think I understand this, but evidently not...monkey-see, monkey-do):

db.define_table('Person_certification',
                Field('Person', db.Person),
                Field('Certification', db.Certification),
                Field('Start_date', 'date',
                  requires=IS_NOT_IN_DB(db(db.Person_certification.Person==request.vars.Person
                                           & dp.Person_certification.Certification==request.vars.Certification),
                                        'Person_certification.Start_date')),
                Field('End_date', 'date'),
                format='%(Person)s %(Certification)s')

The three fields are Person, Certification, and Start_date. When I try to use this I get:

<type 'exceptions.KeyError'> 'Person_certification'

The traceback refers to the 'requires' line. (There's already data in the table (and no duplicates on the three fields); is the code trying to make that check during a SELECT?)

What am I missing here?

Community
  • 1
  • 1
MichaelF
  • 149
  • 1
  • 8

1 Answers1

1

Sorry, original answer was incorrect (fixed now). Because the table hasn't been defined yet, you cannot refer to it in the table definition itself. Instead, set the validator after the table definition:

db.Person_certification.start_date.requires = IS_NOT_IN_DB(...)
Anthony
  • 25,466
  • 3
  • 28
  • 57
  • Perfect. Also had to parenthesize terms to come up with: db.Person_certification.Start_date.requires = IS_NOT_IN_DB(db((db.Person_certification.Person==request.vars.Person) & (db.Person_certification.Certification==request.vars.Certification)), 'Person_certification.Start_date'); – MichaelF Jun 26 '12 at 12:36