yes or
db.define_table('Person',
Field('name',length=45),
Field('info','text'),
format = '%(name)s', #### <<< gives you automatic
validator
migrate=False)
db.define_table('Activity',
Field('type',length=45),
Field('start_date','date'),
Field('end_date','date'),
Field('money',length=45),
Field('price','double'),
Field('person_id',db.Person))
Field('extra_info',length=45),
Field('owner_user_id',length=4),
Field('hour','double'),
migrate=False)
On Jan 17, 9:26 pm, Jeff Bauer <[email protected]> wrote:
> Gibran,
>
> Just use db.Person, not db.Person.id:
>
> Field('person_id',db.Person)
>
> You can then specify the dropdown:
>
> db.Activity.person_id.requires = IS_IN_DB(db,
> 'Person.id',
> '%(id)s %(name)s',)
>
> Or formatted however you want it to appear.
>
> BTW: The convention would probably be to use 'person'
> as your field name in Activity, rather than 'person_id'.
>
> Jeff Bauer
> Rubicon, Inc.
>
> On 01/17/2010 08:20 PM, Gibran Rodriguez wrote:
>
> > I have 2 tables
>
> > db.define_table('Person',
> > Field('name',length=45),
> > Field('info','text'),
> > migrate=False)
>
> > db.define_table('Activity',
> > Field('type',length=45),
> > Field('start_date','date'),
> > Field('end_date','date'),
> > Field('money',length=45),
> > Field('price','double'),
> > Field('person_id',db.Person.id <http://db.Person.id>))
> > Field('extra_info',length=45),
> > Field('owner_user_id',length=4),
> > Field('hour','double'),
> > migrate=False)
>
> > so I want to use the Person.id for the field person_id in the table
> > Activity so that I get a drop downlist of the existing ids but I get the
> > following error?
>
> > File "/home/brangi/Desktop/web2py/gluon/sql.py", line 1242, in define_table
> > t = self[tablename] = Table(self, tablename, *fields)
> > File "/home/brangi/Desktop/web2py/gluon/sql.py", line 1476, in __init__
> > if field.type == 'id':
> > File "/home/brangi/Desktop/web2py/gluon/sql.py", line 2383, in __eq__
> > return Query(self, '=', value)
> > File "/home/brangi/Desktop/web2py/gluon/sql.py", line 2788, in __init__
> > right = sql_represent(right, left.type, left._db._dbname,
> > left._db._db_codec)
> > File "/home/brangi/Desktop/web2py/gluon/sql.py", line 502, in
> > sql_represent
> > return str(int(obj))
> > ValueError: invalid literal for int() with base 10: 'id'
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "web2py-users" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> >http://groups.google.com/group/web2py?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en.