Hello to all,
assuming I have in db.py these tables:
db.define_table('items',
Field('item', requires=IS_NOT_EMPTY()),
format='%(item)s'
)
db.define_table('types',
Field('type_name', requires=IS_NOT_EMPTY()),
format='%(type)s'
)
db.define_table('item_type',
Field('item_id', 'reference items'),
Field('types_id', 'reference types')
)
I have for example 50 items and 3 types and I would like to associate into
table item_type any item to a type.
In my mind there is a page with a table with all the items; on the left
there is the neme of the item and on the right a select list with all the
types.
what is the right way to do this with web2py?
in my controller I tried with:
def item_type():
items = db().select(db.items.ALL)
types = db().select(db.type.ALL)
return dict(items=items, types=types)
and into a view:
<form enctype="multipart/form-data" action="{{=URL()}}" method="post">
<table>
{{for en, item in enumerate(items):}}
<tr>
<td>
<input type="hidden" value="{{=item.id}}" name="item_{{=en}}"
/>{{=item.item}}
</td>
<td>
<select name="type_{{=en}}">
<option value="-1">-</option>
{{for type in types:}}
<option
value="{{=type.id}}">{{=type.type_name}}</option>
{{pass}}
</select>
</td>
</tr>
{{pass}}
<tr>
<td><input type="submit" value="{{=T('Submit')}}" /></td>
</tr>
</table>
It's the right way or I can do something better?
thanks in advance
--
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.