[web2py] Re: IS_NOT_IN_DB failing to create a dropdown?

2011-02-05 Thread SethKinast
Thank you for the clarification. Previous messages on the list seemed
to imply that IS_NOT_IN_DB would also be represented as a dropdown,
but glad to know I made the correct choice in the end.

Cheers!

On Feb 5, 9:43 am, DenesL  wrote:
> The default widget for a field with an IS_NOT_IN_DB requires is a text
> box.
> Your interpretation of how it should work is just one of possibly
> many.
> Think of it this way, the values in the db are a definite set, so you
> can create a list to choose one or many among them; the values that
> are not part of the db yet may not defined and can possibly be
> infinite e.g. books, stars, etc., so you can not list them.
>
> In your case the db has all possible values but web2py does not know
> this.
> The solution is to use the complement of the set, all_booths minus
> leased_booths = free_booths, which is what you did.
>
> On Feb 4, 2:19 pm, SethKinast  wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > First off, I've already fixed my problem by coding it differently.
> > However, I was curious as to the proper way to set up this validator
> > so it shows a dropdown.
>
> > I have two models, which can be simplified to:
>
> > db.define_table('booth',
>
> > Field('name','string',length=10,required=True,notnull=True,unique=True))
> > db.define_table('lease',
> >                 Field('booth',db.booth),
> >                 Field('end_date','date'))
>
> > When creating a new "lease", the SQLFORM field to pick a "booth" to
> > attach should only show booths which have no lease. So I added this in
> > the controller:
>
> > def new():
> >     db.lease.booth.requires = IS_NOT_IN_DB(db(db.lease.end_date ==
> > None)),'lease.booth')
>
> > This promptly transformed the booth dropdown into a text box. It
> > worked fine if, when testing, I used IS_IN_DB instead (showing only
> > booths with current leases, which is of course backwards, but it
> > showed them as a dropdown). I know that if you put the validators in a
> > list they will not create dropdowns, and I made sure that my validator
> > was not in a list.
>
> > So instead I switched to this:
>
> > def new():
> >     leased_booths = db(db.lease.end_date ==
> > None)._select(db.lease.booth)
> >     db.lease.booth.requires =
> > IS_IN_DB(db(~(db.booth.id.belongs(leased_booths))),'booth.id','%
> > (name)s')
>
> > which is a bit less efficient but displays the desired behavior. Is
> > there a more "web2py"-ish way to accomplish this, or is IS_NOT_IN_DB
> > not supposed to display a dropdown? From my reading of the
> > documentation, I thought it was supposed to do so.


[web2py] IS_NOT_IN_DB failing to create a dropdown?

2011-02-04 Thread SethKinast
Hi,

First off, I've already fixed my problem by coding it differently.
However, I was curious as to the proper way to set up this validator
so it shows a dropdown.

I have two models, which can be simplified to:

db.define_table('booth',
 
Field('name','string',length=10,required=True,notnull=True,unique=True))
db.define_table('lease',
Field('booth',db.booth),
Field('end_date','date'))

When creating a new "lease", the SQLFORM field to pick a "booth" to
attach should only show booths which have no lease. So I added this in
the controller:

def new():
db.lease.booth.requires = IS_NOT_IN_DB(db(db.lease.end_date ==
None)),'lease.booth')

This promptly transformed the booth dropdown into a text box. It
worked fine if, when testing, I used IS_IN_DB instead (showing only
booths with current leases, which is of course backwards, but it
showed them as a dropdown). I know that if you put the validators in a
list they will not create dropdowns, and I made sure that my validator
was not in a list.

So instead I switched to this:

def new():
leased_booths = db(db.lease.end_date ==
None)._select(db.lease.booth)
db.lease.booth.requires =
IS_IN_DB(db(~(db.booth.id.belongs(leased_booths))),'booth.id','%
(name)s')

which is a bit less efficient but displays the desired behavior. Is
there a more "web2py"-ish way to accomplish this, or is IS_NOT_IN_DB
not supposed to display a dropdown? From my reading of the
documentation, I thought it was supposed to do so.