I have to use some form of autocomplete input instead of a drop down because there will be a lot of titles, like hundreds, so it would be easier to have people type and have it auto corrected.
I'm still unsure why this code, would return the error: ValueError: invalid literal for int() with base 10: 'Painter'. def search(): searches = db(db.listing.title==request.args(0)).select() items = [] for search in searches: items.append(DIV(A(search, _href=URL('index')))) return TAG[''](*items) Why would it expect an int and not a literal, when my models is: db.define_table('title', Field('name'), format='%(name)s', ) db.define_table(auth.settings.table_user_name, Field('first_name'), Field('last_name'), Field('email'), Field('password','password', length=512, readable=False, label='Password'), Field('title', db.title, '%(name)s'), Field('bio','text'), Field('phone'), Field('website'), Field('address'), Field('registration_key', length=512, writable=False, readable=False, default=''), Field('reset_password_key', length=512, writable=False, readable=False, default=''), Field('registration_id', length=512, writable=False, readable=False, default=''), ) I've got to be missing something??? :/ On Aug 15, 10:01 am, Anthony <abasta...@gmail.com> wrote: > On Sunday, August 14, 2011 7:05:17 PM UTC-4, Jarrod Cugley wrote: > > > Woohoo it's now working! Thank you Anthony!!! > > > 2 questions: > > > 1. When I have > > > listing.title.requires = [IS_IN_DB(db, db.title.id, '%(name)s')] > > > as a list (which is how I want it, it doesn't seem to let me register, > > it still expects an int, how can I make it expect a string that's > > equal to an id? Cause obviously people can't just guess the id of > > their title hahaha > > If you want to enforce the requirement that titles are existing titles in > the 'title' table, why not stick with the dropdown widget instead of > allowing users to enter whatever title they want (which presumably will lead > to more errors)? Another option may be the autocomplete widget > (http://web2py.com/book/default/chapter/07#Autocomplete-Widget), though it > seems to have problems in IE (I hope to come up with a fix for that soon). > Otherwise, I suppose you could write a custom validator that takes the name, > looks up the matching title.id, and changes the value to that id (or returns > an error if not found). > Seehttp://web2py.com/book/default/chapter/07#Custom-Validators. > > > > > 2. I'm running a little test on index to figure out how to display the > > first names that have the reference id '36' using this code: > > > def index(): > > painters = db(db.listing.title == 36).select() > > items = [] > > for painter in painters: > > items.append(DIV(A(painter.first_name, _href=URL('index')))) > > return dict(items=items) > > > But it's just displaying this on the index page: > > > [<gluon.html.DIV object at 0x9982a50>, <gluon.html.DIV object at > > 0x9982b30>] > > 'items' is a list of HTML helpers, not a single HTML helper. If your view > does {{=items}}, it won't serialize the separate DIV objects because they're > part of a list. Instead, you'll need to unpack the list somehow. For > example: > {{for item in items:}} > {{=item}} > {{pass}} > > > P.S Are you the Anthony that was helping me on Stack Overflow too? If > > so thanks, your help is awesome, hopefully I can pay it back one > > day :) > > Yes, same Anthony. No problem, happy to help. Enjoy web2py. :-) > > Anthony