I'm not quite sure what I'm doing wrong here, I'm trying to set up the validation so that you cannot have two units in the same course with the same name (but allow units in different courses to have the same name):
db.define_table('unit', Field('course', db.course), Field('name', required=True), Field('description', 'text'), Field('specification', 'upload'), Field('created_on', 'datetime', default=request.now), Field('created_by', db.auth_user, default=auth.user_id), format='%(name)s') db.unit.created_on.readable = db.unit.created_on.writable = False db.unit.created_by.readable = db.unit.created_by.writable = False db.unit.course.readable = db.unit.course.writable = False db.unit.name.requires = [IS_NOT_EMPTY(), IS_NOT_IN_DB(db(db.unit.course==request.vars.course), db.unit.name)] If I try to create two units with the same name, in the same course, then the validation (incorrectly) allows me to do so. If I remove the section '(db.unit.course==request.vars.course)', then the validation works, but restricts the unit name to only appearing once ever, rather than per course. Does anyone have any helpful suggestions (I am very new to web2py - I only started looking at it a couple of days ago).