You are THE MAN. I did not have to do everything you suggested I only had
to do this:
formcontrol.category.requires =
IS_IN_DB(db(~db.category.title.belongs(notwanted)),'category.id',
label='%(title)s')
Just like magic it showed the value in the DB with no problem.
Thank you this was driving me bonkers!!!
On Tuesday, January 20, 2015 at 9:08:50 AM UTC-6, Anthony wrote:
>
> On Tuesday, January 20, 2015 at 6:07:47 AM UTC-5, americandewd wrote:
>>
>> I have not set any widget controls per what the book specifies shows me
>> can be done for the field.
>>
>> Could you please explain since if I did not set a "widget" then where is
>> this "widget" setting? I have scoured the book and found nothing other
>> than what I copy/pasted here.
>>
>> Am I trying to do something unusual?
>>
>
> Every field gets a default widget based on the field type. Furthermore,
> some validators, such as IS_IN_DB and IS_IN_SET result in particular
> widgets being used unless overridden via the "widget" argument (or unless
> the validator is put in a list). In your case, the IS_IN_SET widget results
> in an HTML <select> element.
>
> Note, reference fields store the integer id values of the records they
> reference, so you should not use an IS_IN_SET validator with category names
> as the elements of the set -- instead, the set should be a list of category
> record id's. You can then pair those id's with labels (i.e., the category
> names), so the HTML select widget shows the names, but the form actually
> submits the integer id of the selected category.
>
> Instead, though, this is typically handled with the IS_IN_DB validator,
> which allows you to define the labels more easily. Note, the first argument
> to IS_IN_DB can be a DAL Set object defining the records that are allowed
> (so you can specify the excluded categories).
>
> Field('category', 'reference category',
> requires=IS_IN_DB(db(~db.category.title.belongs(notwanted)),
> 'category.id', label='%(title)s'),
> represent=lambda category, r: category.title if category else ''
> )
>
> In the above, db(~db.category.title.belongs(notwanted)) defines the set of
> category records whose title is *not *in the notwanted list. The
> validator will select those records and limit valid values for this field
> to the id's of those records. It will also generate a select widget that
> displayes the "title" values in the dropdown.
>
> Anthony
>
>
>
--
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.