If you don't want to add a redundant field to the table, here's another approach: https://groups.google.com/d/msg/web2py/CRPySzABQTk/8jylUabyFTQJ.
Anthony On Monday, December 31, 2012 1:48:25 AM UTC-5, encompass wrote: > > I'll take number 2. :) Looks much cleaner to me! I new about number 1 but > was hoping to see something that sat in the model. Thanks. > BR, > Jason Brower > > > On Sun, Dec 30, 2012 at 8:16 AM, Bruno Rocha > <rocha...@gmail.com<javascript:>> > wrote: > > * can see two options. > > 1. Use form validation: > > > def check_user(form): > query = db.site.user == form.vars.user > query &= db.site.location == form.vars.location > if db(query).count():* > * form.errors.user = "already exists" > > def action(): > form = SQLFORM(db.site) > if form.process(onvalidation=check_user).accepted: > # do whathever > > 2. Create a computed Uni-Key > > * > *db.define_table('site', > Field('location', 'string'), > Field('user', db.auth_user, readable=False, writable=False), > Field('typos', 'blob', readable=False, writable=False, default=None), > Field('status', 'string', readable=False, writable=False, > default='pending'), > Field('last_scan', 'datetime', readable=False, writable=False, > default=None), > Field('unikey' , unique=True, notnull=True, compute=lambda row: > "%(user)d_%(location)s" % row > ) > > > * > On Sun, Dec 30, 2012 at 4:06 AM, encompass <enco...@gmail.com<javascript:> > > wrote: > >> I have this in my model. >> db.define_table('site', >> Field('location', 'string'), >> Field('user', db.auth_user, readable=False, writable=False), >> Field('typos', 'blob', readable=False, writable=False, default=None), >> Field('status', 'string', readable=False, writable=False, >> default='pending'), >> Field('last_scan', 'datetime', readable=False, writable=False, >> default=None) >> ) >> >> db.site.status.requires = IS_IN_SET(['pending', 'working', 'done']) >> db.site.location.requires = IS_URL() >> I want it so that it validates that the combination of db.site.user and >> db.site.location are a unique value. How do I do that in web2py? >> I assume there is a way to do this in the model file and now in a >> controller with checks before insert. >> BR, >> Jason >> >> -- >> >> >> >> > > -- > > > > > > --