Drop down reference not working

7 views
Skip to first unread message

saikatsakura

unread,
Oct 29, 2008, 3:08:20 AM10/29/08
to web2py Web Framework
Hi,

My DB tables are as follows -

#########################################################################
# This scaffolding model makes your app work on Google App Engine
too #
#########################################################################

try:
from gluon.contrib.gql import * # if running on Google App
Engine
except:
db=SQLDB('sqlite://db.db') # if not, use SQLite or other
DB
else:
db=GQLDB() # connect to Google
BigTable
session.connect(request,response,db=db) # and store sessions there
#session.forget() # uncomment for no session
at all

#########################################################################
# Define your tables below, for
example #
#
#
# >>>
db.define_table('mytable',SQLField('myfield','string')) #
#
#
# Fields can be
'string','text','password','integer','double','booelan' #
# 'date','time','datetime','blob','upload', 'reference
TABLENAME' #
# There is an implicit 'id integer autoincrement'
field #
# Consult manual for more options, validators,
etc. #
#
#
# More API examples for
controllers: #
#
#
# >>>
db.mytable.insert(myfield='value') #
# >>>
rows=db(db.mytbale.myfield=='value).select(db.mytable.ALL) #
# >>> for row in rows: print row.id,
row.myfield #
#########################################################################

import datetime
now = datetime.date.today()

db.define_table('category',SQLField('name'))

db.define_table('recipe',
SQLField('title'),
SQLField('description',length=256),
SQLField('category',db.category),
SQLField('date','date',default=now),
SQLField('instructions','text'))

db.category.name.requires =
[IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'category.name')]
db.recipe.title.requires = [IS_NOT_EMPTY()]
db.recipe.description.requires = [IS_NOT_EMPTY()]
db.recipe.category.requires =
[IS_IN_DB(db,'category.id','category.name')]
db.recipe.date.requires = IS_DATE()

However, the dropdown for categories is not coming when trying to add
a recipe. what is the mistake did i do?

regards,
saikat
Message has been deleted

Saikat Chatterjee

unread,
Oct 29, 2008, 4:25:27 AM10/29/08
to web...@googlegroups.com
thanks .... though i figured out the issue. i was putting the "requires" clauses for reference fields inside a []. when i removed it, the code started working....... but thanks anyways bcos it showed me a new technique nonetheless ..............

regards,
saikat

On Wed, Oct 29, 2008 at 1:42 PM, billf <billf...@blueyonder.co.uk> wrote:

The generation of a dropdown list is triggered by IS_IN_SET, e.g.

db.animal.type.requires=IS_IN_SET(['dog','cat','parrot'])

You can generate the option list from the db by something like:

db.animal.type.requires=IS_IN_SET(db().select(db.animals.ALL))

billf

unread,
Oct 29, 2008, 6:10:23 AM10/29/08
to web2py Web Framework
Just out of interest - perhaps everyone knows this...

I have a table "lookup" that contains simple values grouped by type
(counties,countries,person titles,etc) rather than have loads of
different tables. In this case, you can say

db.widget.country.requires=IS_IN_DB(db(db.lookup.type=='Country'),'lookup.id','lookup.value')

On Oct 29, 8:25 am, "Saikat Chatterjee" <saikatsak...@gmail.com>
wrote:
> thanks .... though i figured out the issue. i was putting the "requires"
> clauses for reference fields inside a []. when i removed it, the code
> started working....... but thanks anyways bcos it showed me a new technique
> nonetheless ..............
>
> regards,
> saikat
>
Reply all
Reply to author
Forward
0 new messages