On Thu, Nov 3, 2011 at 4:51 AM, Tom Campbell <[email protected]> wrote:
> ...but I'm too much of a noob to get it.
>
> # file models/db_todo.py
> db.define_table('todo',
> Field('summary','string',requires=IS_NOT_EMPTY()),
> Field('priority',requires=IS_IN_SET([1,2,3,4,5])),
> Field('complete','boolean',default=False))
>
> # file views/main/index.html
> {{extend 'layout.html'}}
> <h2>Current tasks</h2>
> {{=grid}}
>
> # file controllers/main.py
> @auth.requires_login()
> def index():
> # Show only remaining tasks
> todos = db(db.todo.complete==False).select()
> grid=SQLFORM.smartgrid(db.todo,todos)
> return dict(grid=grid)
>
> 1. The main/index.html view is meant to show only completed tasks
> (completed==False). It shows all of them.
>
smartgird does not receives a Rows object as second param, it expects a
dict of table:query
grid=SQLFORM.smartgrid(db.todo,{'todo',db.todo.complete==False})
>
> 2. The dropdowns for Priority start with a blank slot, not 1.
pass zero=None to field requires
Field('priority',requires=IS_IN_SET([1,2,3,4,5], zero=None))
--
Bruno Rocha
[http://rochacbruno.com.br]