On Wed, Apr 28, 2010 at 15:02, Elcimar L. Santos <elci...@gmail.com> wrote: > Hi folks. > > I have a simple table of an sqlite db like this: > > dbOBJECT.define_table("Users", > Field("login", "string", length=80, notnull=True, default=None, > unique=True), > Field("mac1", "string", length=17, notnull=True, default=None, > unique=True), > Field("mac2", "string", length=17, default=None, unique=True), > Field("mac3", "string", length=17, default=None, unique=True), > Field("mac4", "string", length=17, default=None, unique=True)) > > The mac2, mac3, and mac4 fields are not required, they can be None, but > login and mac1 are required. > I also wanted to make sure that no mac fields are inserted twice, even for > different logins, so I used unique=True on all fields, but they can't be > None anymore that way. What should I do?
Hello Elcimar, I think your data model is not very well. It sounds like that you need a table to store MACs, like: db.define_table('User', Field('login', length=80, notnull=True, default=None, unique=True), ) db.define_table('Mac', Field('mac', length=17, notnull=True, default=None, unique=True), Field('user', db.User), ) In [1]: db.User.insert(login='axsad') Out[1]: 1 In [3]: db.Mac.insert(mac='00:15:11:23:45:65', user=1) Out[3]: 1 In [4]: print db().select(db.Mac.ALL) ------> print(db().select(db.Mac.ALL)) Macs.id,Macs.mac,Macs.user 1,00:15:11:23:45:65,1 In [5]: print db().select(db.User.ALL) ------> print(db().select(db.User.ALL)) Users.id,Users.login 1,axsad Nota: você fala Português, então entre na lista web2py-users-brazil e participe da comunidade brasileira e faça suas perguntas lá. :-) http://groups.google.com/group/web2py-users-brazil > Atenciosamente, > > Elcimar Leandro - > http://twitter.com/simakwm > http://elcimar.blogspot.com > Portal Net Fácil - http://www.nfacil.com.br > -- Álvaro Justen - Turicas http://blog.justen.eng.br/ 21 9898-0141