I am trying to create a search filter for categories. The problem, among others, is how the python select is not working the way I mentally would like it. In sqlite I want SELECT * FROM Auctions WHERE Category='arg'. This works on the database when I enter say toys where arg would be. I have category in a dropdown but am unsure how to extract the value. If the search form is used I would like it to just show what category was selected for now and then will work on the price fields.Im just trying to figure out the web.py way to do this. Heres what I have. This is a school project.
Form:
FilterForm = web.form.Form(
web.form.Textbox('Search', web.form.notnull, description="Search:"),
web.form.Dropdown(name='Category', args=[]),
web.form.Textbox('minPrice', web.form.notnull, description="Price Min: "),
web.form.Textbox('maxPrice', web.form.notnull, description="Price Max: ")
web.form.Button('Apply Search Filter')
)
def POST(self):
if not FilterForm.validates():
Auctions = model.filter_auctions(FilterForm.d.Category, FilterForm.d.maxPrice, FilterForm.d.minPrice)
FilterForm.Category.args = [(a.ItemID, a.Category) for a in Auctions]
return render.index(Auctions,
AuctionForm,
Bids,
BidForm,
Logins,
LoginForm,
FilterForm,
TimeForm)
raise web.seeother('/')
Model:
def filter_auctions(category, price_min, price_max):
return db.select('Auction', where="Category=category")
HTML:
<ul id="filtermenu">
<li><a href="#">Add Filter</a><span class="rarrow">▶</span>
<ul class="subF1">
<form action="" method="post">
$:FilterForm.render()
</form>
</ul>
</li>
</ul>
Aucun commentaire:
Enregistrer un commentaire