When I try to add info from the admin, I get a ticket on any table
with foreign fields. Normal tables work fine. Here's the code:
db.define_table('workreq',
Field('date_requested','datetime', notnull=True),
Field('date_needed','date',
requires = IS_NULL_OR(IS_DATE())),
Field('next_run','date',
requires = IS_NULL_OR(IS_DATE())),
Field('last_run','date',
requires = IS_NULL_OR(IS_DATE())),
Field('event', db.event, notnull=True,
requires = IS_IN_DB(db, db.event)),
Field('exclude_from_next','boolean'),
Field('approx_number','integer',
requires = IS_NULL_OR(IS_INT_IN_RANGE(0, 9999))),
Field('print_service','boolean'),
Field('service_name', db.print_service,
requires = IS_NULL_OR( IS_IN_DB(db, db.print_service))),
# These are not real fields! Do not uncomment! These are
# representations of M2Ms
# Field('email_to', db.workXperson),
# Field('outtypes', db.workXtype, notnull=True),
# Field('outopts', db.workXopt, notnull=True),
# Field('sorts', db.workXsorts),
Field('assigner', db.person, notnull=True,
requires = IS_IN_DB(db, db.person)),
Field('worker', db.person,
requires = IS_NULL_OR( IS_IN_DB(db, db.person))),
Field('complete_date','datetime',
requires = [IS_NULL_OR(IS_DATE()), ]),
Field('no_accounts','integer',
requires = [IS_NULL_OR(IS_INT_IN_RANGE(0, 9999)), ]),
Field('rel_report_link','string', length=254,
requires = [IS_LENGTH(254),
IS_NULL_OR(IS_URL()), ]))
Error traceback
Traceback (most recent call last):
File "/var/pysites/workreq2/gluon/restricted.py", line 178, in
restricted
exec ccode in environment
File "/var/pysites/workreq2/applications/workrequest/models/db.py",
line 143, in <module>
requires = IS_IN_DB(db, db.event)),
File "/var/pysites/workreq2/gluon/validators.py", line 340, in
__init__
(ktable, kfield) = str(self.field).split('.')
ValueError: need more than 1 value to unpack
When I quote the foreign references, I get this:
Error traceback
Traceback (most recent call last):
File "/var/pysites/workreq2/gluon/restricted.py", line 178, in
restricted
exec ccode in environment
File "/var/pysites/workreq2/applications/workrequest/controllers/
appadmin.py", line 410, in <module>
File "/var/pysites/workreq2/gluon/globals.py", line 96, in <lambda>
self._caller = lambda f: f()
File "/var/pysites/workreq2/applications/workrequest/controllers/
appadmin.py", line 124, in insert
form = SQLFORM(db[table], ignore_rw=ignore_rw)
File "/var/pysites/workreq2/gluon/sqlhtml.py", line 696, in __init__
inp = self.widgets.options.widget(field, default)
File "/var/pysites/workreq2/gluon/sqlhtml.py", line 187, in widget
options = requires[0].options()
File "/var/pysites/workreq2/gluon/validators.py", line 391, in
options
self.build_set()
File "/var/pysites/workreq2/gluon/validators.py", line 375, in
build_set
records = self.dbset.select(*self.fields, **dd)
File "/var/pysites/workreq2/gluon/sql.py", line 3110, in select
query = self._select(*fields, **attributes)
File "/var/pysites/workreq2/gluon/sql.py", line 2994, in _select
w2p_tablenames = [ t for t in tablenames if
isinstance(self._db[t],Table) ]
File "/var/pysites/workreq2/gluon/sql.py", line 1323, in __getitem__
return dict.__getitem__(self, str(key))
KeyError: 'db'