Is "Plumber" being entered in the 'title' field of the user table? If so,
that field is expecting an integer because it is a reference to the 'id'
field of the 'title' table (which is an integer field).
listing.title.requires = [IS_IN_DB(db, db.title.name)]
Your validator, on the other hand, is requiring a string that is one of the
names stored in db.title.name. So, your form/validator wants a string, but
the database wants an integer. You can change your validator to:
listing.title.requires = [IS_IN_DB(db, db.title.id, '%(name)s')]
Note, because the validator is inside a list, it will not display the
typical dropdown for an IS_IN_DB validator. If you want the dropdown, take
it out of the list. Also, if you simply add format='%(name)s' to your
'title' table definition, you don't have to bother specifying the validator
for the listing.title field at all because the default validator will be the
above IS_IN_DB validator anyway.
See http://web2py.com/book/default/chapter/07#Database-Validators and
http://web2py.com/book/default/chapter/06#Record-Representation.
Anthony
On Sunday, August 14, 2011 5:39:27 AM UTC-4, Jarrod Cugley wrote:
> Hi guys this is my first post so just let me know if I'm doing
> anything wrong :) (Massimo recommended I ask questions here about
> web2py rather than on Stack Overflow)
>
>
> As the title says: I keep getting the error: invalid literal for int()
> with base 10: 'Plumber'
> I've done searching and it seems to be a common error, but I can't
> figure out how to fix it from the answers I've already read, here is
> my code (that I think is the needed code to solve the error):
>
> ___DB.PY___: (model)
>
> db.define_table('title',
> Field('name'),
> )
>
> 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),
> 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=''),
> )
>
> listing = db[auth.settings.table_user_name]
> listing.title.requires = [
> IS_IN_DB(db, db.title.name)]
>
>
>
> ___DEFAULT.PY___: (controller)
>
> def index():
> painters = db(db.listing.title == 23).select()
> items = []
> for painter in painters:
> items.append(A(painter.first_name, _href=URL('index')))
> return dict(items=items)
>
>
> In my view I just have {{=items}}
>
> On top of this I can't create new users from the registration form or
> the appadmin, because it brings up the same error when I submit both
> registration forms.
>
> I'm so confused (because I'm an obvious newbie :P) any help would be
> greatly appreciated! :)