Correction!

It can be done but in two steps:

db.define_table('person',SQLField('name'))
db.define_table('project',SQLField('name'))
db.define_table('relation',
  SQLField('person_id','reference person'),
  SQLField('project_id','reference project'))
db.relation.person_id.requires=IS_IN_DB(db,db.person.id,'%(name)s')
db.relation.project_id.requires=[IS_IN_DB(db,db.project.id,'%(name)
s'),
  IS_NOT_IN_DB(db
(db.relation.person_id==request.vars.person_id),db.relation.project_id)]

because the last line sets 2 validators, there is no automatic
dropbox. It must be added via a widget with a trick (clone the field)

from gluon.html import OptionsWidget
db.relation.project_id.widget=lambda f,v: OptionsWidget.widget(SQLField
('project_id',db.project,requires=db.relation.project_id.requires
[0]),v)

This should work but I will make it easier and more intuitive.

Massimo

On Jun 20, 11:23 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> The code you have below works fine. I guess the question is how to do
> IS_IN_DB and IS_NOT_IN_DB at the same time for the same field. Is that
> the question? If so: you cannot unless you define your own validator.
> I agree there should be an option to do it and I can add one.
>
> massimo
>
> On Jun 20, 8:34 pm, DenesL <denes1...@yahoo.ca> wrote:
>
> > Massimo, this simple scenario should be possible, but how?.
>
> > model:
> > db.define_table('person',SQLField('name'))
> > db.define_table('project',SQLField('name'))
> > db.define_table('relation',
> >   SQLField('person_id','reference person'),
> >   SQLField('project_id','reference project'))
> > db.relation.person_id.requires=IS_IN_DB(db,db.person.id,'%(name)s')
> > db.relation.project_id.requires=IS_IN_DB(db,db.project.id,'%(name)s')
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to