2012-06-26 3 views
1

나는 테이블에서 고유해야하는 세 개의 필드가 있고 answer to this question을 기반으로 다음을 시도했습니다. ( 나는 이것을 이해하지만 분명히 ... 원숭이처럼 보이지 않습니다. 원숭이-DO) : web2py의 3 필드 합성 키

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') 

세 필드

는 사람, 인증 및 START_DATE이다. 내가 이것을 사용하려고하면 내가 얻을 :

<type 'exceptions.KeyError'> 'Person_certification'

역 추적은 '필요'라인을 의미합니다. (이미 테이블에 데이터가 있고 (세 개의 필드에 중복이 없음) 코드가 SELECT 중에 해당 체크를하려고합니까?

여기서 내가 무엇을 놓치고 있습니까?

답변

1

죄송합니다. 원래 답변이 잘못되었습니다 (지금 수정 됨). 테이블이 아직 정의되지 않았기 때문에 테이블 정의 자체에서 테이블을 참조 할 수 없습니다. 대신 테이블 정의 뒤에 유효성 검사기를 설정하십시오.

db.Person_certification.start_date.requires = IS_NOT_IN_DB(...) 
+0

완벽합니다. 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