Hi Calycé,

note that:
store.category.parent_category.requires = 0 or IS_IN_DB(db,
db.category.id, '%(name)s')
is equivalent to:
store.category.parent_category.requires = IS_IN_DB(db, db.category.id,
'%(name)s')
since 0 evaluates to False.

I believe that what you want is:
store.category.parent_category.requires = IS_EMPTY_OR(IS_IN_DB(db,
db.category.id, '%(name)s'))

Denes.

On Oct 21, 3:35 am, Calycé <[email protected]> wrote:
> Hi all,
>
> I have created a table with a self reference as described below:
> db.define_table('category',
>     Field('parent_category', 'reference category'),
>     Field('name', 'string', length=40, required=True),
>     Field('description', 'text', required=True),
>     Field('small_image', 'upload'))
>
> Now I'd like to have an "optional requires" clause. For example, if I
> add the following clause "store.category.parent_category.requires = 0
> or IS_IN_DB(db, db.category.id, '%(name)s')" I have a nice combo
> whenever I use the appdadmin to insert rows BUT I have to select
> something from the combo. In my case, the parent_category field should
> be optional. In extenso, categories without parent_category would be
> root categories so selecting a parent_category is optional.
>
> Is there a way to present a combo as does the "requires" but without
> enforcing the field ? Do I have to create a specific form for that ?

Reply via email to