Hi,

I have a pretty simple model, which is very similar to one commonly
referenced in the web2py book:

db.define_table('person',
    Field('name', requires=IS_NOT_EMPTY()))
db.define_table('dog',
    Field('owner', db.person),
    Field('name', requires=IS_NOT_EMPTY()))

db.dog.owner.requires = IS_IN_DB(db,db.person.id,'%(name)s')

Now, what I'm wanting to do is place a restriction on dog names.
Different dog owners can have dogs of the same name, but no single
person can own 2 or more dogs of the same name. It's not obvious to me
how to use IS_IN_DB() to accomplish this, since that will disallow
different owners from having a common dog name.

The problem that I'm seeing is that when you want to add a new dog to
the database, you have to have some way of referencing the owner to
which the dog will belong when you do the validations, so that you can
check all the dogs that certain owner already owns. I've looked into
custom validators a bit, but I'm not sure how to do this. Can anyone
offer some advice on how to accomplish this? Thanks!

Reply via email to