def show_matches():
matches = db(db.matches.id > 0).select()
return dict(matches=matches)
{{extend 'layout.html'}}
<h1>MATCHES</h1>
<table>
<th>
<th>MATCH</th>
<th>TEAM1</th>
<th>TEAM2</th>
</th>
{{for match in matches:}}
<tr>
<td>{{=match['team1']}} vs. {{=match['team2']}}</td>
<td>
<forms>
<select style="width:80px;">
<option>0</option>
<option>1</option>
<option>2</option>
<option>+2</option>
</select>
</form>
</td>
<td>
<forms>
<select style="width:80px;">
<option>0</option>
<option>1</option>
<option>2</option>
<option>+2</option>
</select>
</form>
</td>
</tr>
{{pass}}
</table>
You are doing this the really hard way, I think.If you read the book a bit more you will discover web2py's built-in forms.Probably you should use SQLFORM.This means you do all the coding in the controller. Behind the scenes, SQLFORM will create a variable which contains the HTML to display the form, and it also includes the logic to update the database table.While you are developing, you can rely on the "developer" or generic views, which means you don't even need to worry about making a view until you are ready.In other words, you can do all of this in one line (in the controller)form = SQLFORM(db.matches)(assuming you have setup up your table definition well).Or you should read about SQLFORM.grid, which may be more what you want. It starts by displaying all the records in a table, and then lets the user choose which rows to edit. It then automatically generates an SQLFORM for that row. Still only one line :)
On Friday, 18 October 2013 10:22:40 UTC+11, Wonton wrote:
A grid means a button to go to an edit form. An inline edit solution is possible but more advanced, not out of the box.
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/1W73GQvGVEA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.