Thank you! That worked perfect!!
Now I have a doubt, It works as I need it, but if I want to show what the
user selected in a view, what should I do?
I have this view
{{extend 'layout.html'}}
<center><h3>You are currently seeing {{=request.vars.category}}
books.</h3></center>
{{=form}}
{{=table}}
It works but it shows the category ID, how could I show the name??
and one more thing, I have a custom auth user table with an extra field
(category) so a user has a default category. This category is the same
category I'm using in the search filter (dropdown) how could I show to the
logged user his default category?
So for example if I'm registered in the horror category, when I login how
could I have the filter set by default to horror? And of course if I select
another category I'll have the filter functionality.
On Mon, Feb 21, 2011 at 7:36 PM, Brian M <[email protected]> wrote:
> Correction should be
> requires=IS_IN_DB(db(db.category.id>0),...)
> not requires=IS_IN_DB(db.category,...)
>
>
> form = SQLFORM.factory(Field("category",label="Book Category",
> requires=IS_IN_DB(db(db.category.id>0), 'category.id', 'category.name',
> error_message="Please pick a category from the list")))
>
> if form.accepts(request.vars, session, keepvalues=True):
>
> powerTable = plugins.powerTable
> powerTable.datasource =
> db(db.book.category==request.vars.category).select(db.category.ALL)
> #DAL query!
> powerTable.headers = 'labels' #Add a label="some text" to your fields
> in the model & it'll be used else it'll try to use the field's name
> powerTable.columns=['book.name', 'book.code']
> books = powerTable.create()
> else:
> books = None
> return dict(form = form, books = books)
>