Just to close the loop on this, it works.
I put this assignment in the model between the db.define_table()
statements and the validators...
rows=db(db.Assessment.InfoSys_id==db.InfoSys.id).select
(db.InfoSys.ALL,db.Assessment.ALL,orderby=db.InfoSys.ISName)
...and this validator after it (along with many others) at the end of
the model file...
db.Doc.Assessment_id.requires=IS_IN_SET([r.Assessment.id for r in
rows], ["%s %s %s" % (r.InfoSys.ISName,
r.Assessment.AssessmentDateStart, r.Assessment.AssessmentDateEnd) for
r in rows])
The two statements above are somewhat different from what Massimo
initially suggested, but the same basic idea.
Now *why* it works is a little puzzling. From the web2py manual...
IS_IN_SET checks that the field values are in a set: requires=IS_IN_SET
(['a','b','c'],error_message=T('must be a or b or c'))
Notice IS_IN_SET has two arguments - the 'set' (a list of strings),
and an error message in case it fails.
The IS_IN_SET I'm using also has two arguments - from the first is the
foreign key that's inserted in the doc.Assessment_id field, and the
second populates the doc.Assessment_id drop down list in the 'New
Record' form. I never would have figured IS_IN_SET could do what it's
doing, but it is. Not intuitive to say the least.
BTW, I want to second DenesL's comment - if this can be added as a
web2py native capability with minimal effort that would be a VERY good
thing.
Thanks for the help.
On Feb 16, 8:36 am, mdipierro <[email protected]> wrote:
> It is not possible but it should be possible with a minor
> modification. Let me know bout this..
>
> for now you can use
>
> rows=db(db.Assessment.InfoSys_id==db.InfoSys.id).select
> (db.InfoSys.ISName, db.Assessment.ALL)
> requites=IS_IN_SET([r.InfoSys.id for r in rows],["%s %s %s" %
> (r.InfoSys.ISName, r.Assessment.AssessmentStartDate, r.
> Assessment.Assessment.DateEnd) for r in row])
>
> It is not that different. The only difference is that depending on
> where you put this, you would be doing the query even if you do no not
> need the validator.
>
> Massimo
>
> On Feb 15, 11:24 pm,ctalley<[email protected]> wrote:
>
>
>
> > Based on this partial model...
>
> > db.define_table('InfoSys',
> > SQLField('ISName', 'string'),
> > SQLField('ISAbbrev', 'string'),
> > SQLField('ISType_id', db.ISType),
> > SQLField('AppQuarter_id', db.AppQuarter),
> > SQLField('ISOwnerType_id', db.ISOwnerType))
>
> > db.define_table('Assessment',
> > SQLField('InfoSys_id', db.InfoSys),
> > SQLField('AssessmentDateStart', 'date'),
> > SQLField('AssessmentDateEnd', 'date'),
> > SQLField('CAType_id', db.CAType),
> > SQLField('AssessmentType_id', db.AssessmentType))
>
> > db.define_table('Doc',
> > SQLField('Assessment_id', db.Assessment),
> > SQLField('DocList_id', db.DocList),
> > SQLField('DocVersionType_id', db.DocVersionType),
> > SQLField('ClientStatusType_id', db.ClientStatusType),
> > SQLField('ClientStatusDate', 'date'),
> > SQLField('ClientStatusNote', 'text'))
>
> > ... assume I am adding a new Doc record through "database
> > administration" on the Design tab (appadmin).
>
> > I want the Assessment_id field to be a drop down list containing three
> > pieces of information, all of which are in the referenced table
> > Assessment...
> > InfoSys_id
> > AssessmentDateStart
> > AssessmentDateEnd
>
> > Now, in order to do this, I can create a validator something like
> > this...
>
> > db.Doc.Assessment_id.requires=IS_IN_DB(db,db.Assessment.id,'%
> > (InfoSys_id)s %(AssessmentDateStart)s %(AssessmentDateEnd)s')
>
> > Perfect. So far, so good. But here's my problem - InfoSys_id is a
> > foreign key and thus a number. What I really want is the data that
> > number represents, which is InfoSys.ISName. How is it possible (or is
> > it possible) to represent InfoSys_id as InfoSys.ISName, along with the
> > two dates, in a drop down list? I wrote a join query that returns the
> > required information, but can't figure out syntactically how to stuff
> > it into the validator (assuming it's even possible)...
>
> > db(db.Assessment.InfoSys_id==db.InfoSys.id).select(db.InfoSys.ISName)- Hide
> > quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" 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
-~----------~----~----~----~------~----~------~--~---