El martes, 26 de agosto de 2014 22:49:17 UTC+2, Anthony escribió:
>
>
>
> On Tuesday, August 26, 2014 3:13:35 PM UTC-4, José L. wrote:
>>
>> Hi, I'm using a custom form to represent the fields of a table. This
>> table has referenced fields.
>> If I use:
>> db.define_table('department',
>> Field('dept_id'),
>> Field('nombre'),format='%(nombre)s')
>>
>> db.define_table('employee',
>> Field('firstName'),
>> Field('lastName'),
>> Field('dept_id', db.department))
>>
>> The table employee represents correctly the dept names. But if I do:
>>
>>
>> db.define_table('employee',
>> Field('firstName'),
>> Field('lastName'),
>> Field('dept_id', db.department), requires=IS_EMPTY_OR(IS_IN_DB(db,
>> db.department.id,
>> '%(nombre)s')))
>>
>
> I assume the above is a typo -- should be:
>
> Field('dept_id', db.department, requires=IS_EMPTY_OR(IS_IN_DB(db, db.
> department.id,
> '%(nombre)s'))))
>
>
Yes, it was a typo.
> {{=form.custom.widget.dept_id}} shows the departament id instead of the
>> name.
>> I need to add the "IS_EMPTY_OR" condition, I've also tried adding
>> notnull=False without success.
>>
>
> Are you saying that in a create or update form, the select dropdown
> includes a list of IDs rather than names, or that in a grid or read-only
> form you see IDs rather than names? The former should not be the case, and
> when I try it, I see a list of names. If the latter is the problem, that is
> because you have not defined a "represent" attribute for the dept_id field
> (if you explicitly specify a "requires" argument when defining a reference
> field, you do not get the automatic "represent" attribute defined, so you
> have to define that explicitly as well).
>
> Anthony
>
It was the latter case. It worked when using a create form but not with the
view. I didn't know that requires removed the "representation", I can not
recall reading that in the documentation either. Now it works perfectly in
both cases adding the represent attribute to the field definition:
represent = lambda id, row: db.department._format % db.department(id)
Thanks very much for your help.
José L.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.