Hi everybody,
since a couple of days I am trying to implement a *normalized many-to-many
model* that can be managed using a single form consisting of a couple of
fields from one table and a multiple select drop-down list containing
references to an intersection table.
My problem is an exception that is thrown when the form is validated after
submit:
int() argument must be a string or a number, not 'list'
The exception is caused by a list of reference ids defined by selected
options in the drop-down list.
A way to circument this exception might be to denormalize the intersection
table by using the field type list:reference which I want to avoid for
various reasons.
I have created a similar model for demonstration purposes, where the entity
package has one or many components:
db.define_table('component',
Field('some_field'),
format='%(some_field)s'
)
db.define_table('package',
Field('another_field'),
format='%(another_field)s'
)
db.define_table('component_package_association',
Field('component_id', 'reference component'),
Field('package_id', 'reference package'))
db.component_package_association.component_id.requires = IS_IN_DB(
db, 'component.id', '%(some_field)s', multiple=True)
And the controller:
def manage_packages():
if request.args(0) == 'new' and request.args(1) == 'package':
form = SQLFORM.factory(db.package,
db.component_package_association)
if form.process().accepted:
# Code to store the new package and associations to
components
# ...
response.flash = 'Package successfully created.'
content = form
else:
content = SQLFORM.grid(db.package)
return dict(content=content)
I did some research in the web2py-users ML and some search engines but
could not find a way to tackle this issue.
Following a couple of ideas for which I am thankful to get helpful comments
and advice:
1. Create a custom validator for the form or
2. Disable form.process().accepted or
3. Disable the validation for the specific field
4. Something completely different
I try to avoid options 2 and 3.
Thank you for your time!
//jotbe
--
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.