0

I am trying to use the method posted by Anthony

db.define_table('ts_customer',
            Field('customer_name', 'string', length=80, required=True, unique=True))

db.define_table('ts_mileage_rate',
            Field('customer_id', 'reference ts_customer', required=True, notnull=True),
            Field('mileage_rate_year', 'integer', required=True, notnull=True,
                  requires=IS_NOT_IN_DB(
                      db(db.ts_mileage_rate.customer_id == request.vars.customer_id),
                      'ts_mileage_rate.mileage_rate_year')
            ))

I get the following error:

type 'exceptions.AttributeError'> 'DAL' object has no attribute 'ts_mileage_rate'

Any idea why?

Community
  • 1
  • 1
user1930143
  • 191
  • 1
  • 3

1 Answers1

0

You have db.ts_mileage_rate.customer_id within the definition of the ts_mileage_rate table, so the table doesn't yet exist. Instead, define the requires attribute after the table definition:

db.ts_mileage_rate.mileage_rate_year.requires = IS_NOT_IN_DB(
    db(db.ts_mileage_rate.customer_id == request.vars.customer_id),
    'ts_mileage_rate.mileage_rate_year')
Anthony
  • 25,466
  • 3
  • 28
  • 57