Anthony, work fine, man! Reading the web2py book I realized that the problem was in requires and not in required, but had not understood well what he expects. Now yes! I also didn't know about the argument _represent!
Thank you very much, man! On Sat, Jan 26, 2013 at 1:31 PM, Anthony <[email protected]> wrote: > I assume you're getting an error message on the form itself, which > indicates the problem is with the default validator, not the notnull > attribute (the latter is set in the database and results in a database > error, which results in web2py returning a 500 server error response if not > otherwise trapped). By default, your reference field gets this validator: > > IS_IN_DB(db, 'logr_type.id', db.logr_type._format) > > That gives you the dropdown list in the form but also requires that a > selection be made. To enable the dropdown but not require a selection, you > can do: > > Field('logr_type', 'reference logr_type', notnull=False, label=T('Logr > Type'), > requires=IS_EMPTY_OR(IS_IN_DB(db, 'logr_type.id', '%(name)s')), > represent=lambda id, r: db.logr_type[id].name) > > Note, that code also explicitly sets the "represent" attribute of the > field. The reason is that when you explicitly set the "requires" attribute > of a reference field, the default "represent" attribute is no longer set > automatically. > > Anthony > > > On Saturday, January 26, 2013 7:04:24 AM UTC-5, __pyslan__ wrote: >> >> My models: >> >> LogrType = db.define_table('logr_type', >> Field('name', notnull=False, label=T("Name")), >> format='%(name)s' >> ) >> >> Venture = db.define_table('venture', >> Field('venture_type', 'reference venture_type', notnull=True, >> label=T("Type")), >> Field('venture_situation', 'reference venture_situation', >> notnull=True, default=1, label=T("Situation")), >> Field('name', notnull=True, label=T("Name")), >> Field('logr_type', 'reference logr_type', notnull=False, >> label=T('Logr Type')), >> Field('logr', notnull=False, label=T('Logradouro')), >> Field('logr_number', notnull=False, label=T('Number')), >> Field('logr_compl', notnull=False, label=T('Complement')), >> Field('logr_neigh', notnull=False, label=T('Neighborhood')), >> Field('logr_city', notnull=False, label=T('City')), >> Field('logr_state', notnull=False, label=T('State')), >> Field('logr_zip_code', notnull=False, label=T('Zip Code'), >> default=""), >> format='%(name)s' >> ) >> >> >> When I add, or edit a venture, the logr_type is required...and should not >> be.. >> >> >> Thanks... >> >> __pyslan__ >> >> -- > > > > --

