Il 28/12/2010 23:40, Luther Goh Lu Feng ha scritto:
Is there a reason why you are not using Auth, if you aren't?

http://www.web2py.com/book/default/chapter/08#Authentication

Anyway, assuming that you truly want to add the unique constraint,
then I am guessing that you could construct virtual fields

http://www.web2py.com/book/default/chapter/06#Virtual-Fields

and apply the constraint 
http://www.web2py.com/book/default/docstring/IS_NOT_IN_DB

db.page.title.requires = IS_NOT_IN_DB(db, 'page.title') #http://
www.web2py.com/book/default/chapter/03
interesting answer, but trying what is suggested ti seams not possible to refer to a virtual field such as it's possible with real fields... I mean trying this little example that's the result I get

>>> db.define_table('mytable',
...   Field('field1','integer'),
...   Field('field2','integer'),
... )
>>> class MyVirtualFields(object):
...   def uniqueField(self):
...     d = dict()
...     for i in ['field1', 'field2']:
...       d[db.mytable[i].name] = self.mytable[i]
...     return d
...
>>> db.mytable.virtualfields.append(MyVirtualFields())
>>> db.mytable.uniqueField.requires = IS_NOT_IN_DB(db, 'mytable.uniqueField')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
File "/home/manuele/Progetti/web2py/gluon/sql.py", line 1688, in __getattr__
    return dict.__getitem__(self,key)
KeyError: 'uniqueField'

what's wrong in it?

thank you very much

    Manuele

Reply via email to