Is there any way to make a field in a form referencing a foreign key null, while storing a foreign key as a foreign key, but making dropdowns corrospond to the format. Here is my example:
db = DAL('sqlite://storage.sqlite')
db.define_table('person',
Field('name'),
Field('email'),
format = '%(name)s')
db.define_table('dog',
Field('name'),
Field('owner', requires = IS_EMPTY_OR(IS_IN_DB(db,db.person))), #I have also tried default=None, and required = False, no difference
format = '%(name)s')
Controller:
from gluon.tools import Crud
crud = Crud(db)
def index():
form = SQLFORM(db.person)
if form.process().accepted:
response.flash = 'success'
return dict(form=form)
def add_dog():
form = SQLFORM(db.dog)
if form.process().accepted:
response.flash = 'success'
return dict(form=form)
def view():
grid = SQLFORM.smartgrid(db.dog)
grid2 = crud.select(db.person)
return dict(grid=grid, grid2=grid2)
When I have the above code, a foreign key will be stored in the database, but all views of that key will be rendered as the numerical value of the foreign key, and not the name. In the table definition, if I just have db.person instead of requires = IS_EMPTY_OR(IS_IN_DB(db,db.person)), It requires the field.
Are there any workarounds?
-Joe Peacock