Yup, of course, you are right as usual Mr. MDP. Which is why I want to fatten you up so you'll slow down a little and let ordinary mortals like me catch up. My mistake was in the IS_IN_DP syntax. I lied in my earlier note where I said that I did exactly what you wrote. In fact, I had written almost exactly what I put in my original note to open this thread. I'm closing this and moving on. THANKS!
On Jan 24, 11:06 pm, mdipierro <[email protected]> wrote: > This defines the field as a reference > > Field('make',db.car_makers) > > This makes the dropdown > > db.car.make.requires = IS_IN_DB(db,db.car_makers.id,'%(name)s') > > This selects the default option on create forms (not on update forms) > and caches it > > db.car.make.default = db(db.car_makers.name=='Ford').select > (db.car_makers.id,cache=(cache.ram,3600)).first().id > > This MUST work. > > On Jan 24, 9:17 pm, weheh <[email protected]> wrote: > > > When I go to the URL that displays the form, I see Edsel in the > > pulldown, not Ford. p.s. I've never used caching. Do you have a quick > > answer for how to do it? Thx. - RG > > > On Jan 24, 10:12 pm, mdipierro <[email protected]> wrote: > > > > how doesn't work? > > > > P.S. you should cache this for speed: > > > > db.car.make.default = db(db.car_makers.name=='Ford').select > > > (db.car_makers.id,cache=(cache.ram,3600)).first().id > > > > On Jan 24, 9:01 pm, weheh <[email protected]> wrote: > > > > > Sorry. I was writing off the top of my head. Of course, I did exactly > > > > what you wrote in my actual code. Still doesn't work. > > > > > On Jan 24, 9:53 pm, mdipierro <[email protected]> wrote: > > > > > > I think you want: > > > > > > Field('make',db.car_makers,IS_IN_DB(db,db.car_makers.id,'%(name)s') > > > > > > and > > > > > > db.car.make.default = db(db.car_makers.name=='Ford').select > > > > > (db.car_makers.id).first().id > > > > > > On Jan 24, 8:46 pm, weheh <[email protected]> wrote: > > > > > > > I'm certain this has been asked a bunch of times. I've spent the > > > > > > last > > > > > > hour looking for it but can't find it anywhere. Sorry. > > > > > > > The question is how to set the default value of a reference field > > > > > > based on a query of the referenced table. > > > > > > > db.define_table('car_makers',Field('name',unique=True)) > > > > > > db.define_table('car', > > > > > > Field('make',db.car_makers,IS_IN_DB(db,'car_makers.name','%(name) > > > > > > s')), > > > > > > Field('model')) > > > > > > > I want to set > > > > > > db.car.make.default=db(db.car_makers.name=='Ford').select > > > > > > (db.car_makers.id)[0] > > > > > > so that when I do an SQLFORM, the drop down list of db.car.make will > > > > > > pre-select "Ford". > > > > > > > This isn't working for me. What am I doing wrong? -- 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.

