Hello,

It is my first message in this forum. I am trying to learn web2py and 
Python. So, sorry with stupid and simple questions. I decided to post a 
question here because I used a lot the on line documentation and forum but 
I am not finding the solution.

My project is to manage services but multiple services centers and each one 
can define their services. So, I created a table for services, another one 
for services per center. The table to post the executed service, I want to 
show the service name, stead of the id.

You can see below the tables, querys that I am using.

#service types
db.define_table(
    'tipo_servicos',
    Field('servico', label='Serviço'),
    format = '%(servico)s')

#services per service center, named here as oficina
db.define_table(
    'servico_oficiona',
    Field('id_oficiona',  label='Oficina'),
    Field('servico_oficiona', db.tipo_servicos),
    Field('pontos', 'integer', label='Pontos')
    )

#posting executed services
db.define_table(
'servicos_feitos',
Field('oficiona', label='Oficina', writable=False),
Field('cliente', label='Cliente'),
Field('servico_feito', label='Serviço'),
Field('data_servico', 'date',default=datetime.date.today(), label='Data 
Serviço')
    )

#query to filter only customers for the service center
querycli=db(db.cliente.oficiona==auth.user.id)
db.servicos_feitos.cliente.requires = IS_IN_DB(querycli, 'cliente.id', 
'%(nome)s')

*Everything is perfect at this point .I am using SQLFORMAT and it's ok.*
* The problem is here:*

#query to link service types + services per service center
queryser=db((db.servico_oficina.id_salao==auth.user.id)& 
(db.servico_oficina.servico_salao==db.tipo_servicos.id))

db.servicos_feitos.servico_feito.requires = IS_IN_DB(queryser, 
db.servico_oficiona.id, '%(servico)s')

I tried also to use SQLFORMAT.factory and use IS_IN_SET with this query, 
but, the selection list is a object like 'row', I believe. 

The error is here.

Traceback (most recent call last):
  File "/home/andre/Dropbox/Projetos/web2py/gluon/restricted.py", line 227, in 
restricted
    exec ccode in environment
  File 
"/home/andre/Dropbox/Projetos/web2py/applications/fideliza/controllers/default.py"
 <http://127.0.0.1:8000/admin/default/edit/fideliza/controllers/default.py>, 
line 152, in <module>
  File "/home/andre/Dropbox/Projetos/web2py/gluon/globals.py", line 417, in 
<lambda>
    self._caller = lambda f: f()
  File "/home/andre/Dropbox/Projetos/web2py/gluon/tools.py", line 4250, in f
    return action(*a, **b)
  File 
"/home/andre/Dropbox/Projetos/web2py/applications/fideliza/controllers/default.py"
 <http://127.0.0.1:8000/admin/default/edit/fideliza/controllers/default.py>, 
line 140, in novo_servico_feito
    form = SQLFORM(db.servicos_feitos)
  File "/home/andre/Dropbox/Projetos/web2py/gluon/sqlhtml.py", line 1295, in 
__init__
    inp = self.widgets.options.widget(field, default)
  File "/home/andre/Dropbox/Projetos/web2py/gluon/sqlhtml.py", line 313, in 
widget
    options = requires[0].options()
  File "/home/andre/Dropbox/Projetos/web2py/gluon/validators.py", line 600, in 
options
    self.build_set()
  File "/home/andre/Dropbox/Projetos/web2py/gluon/validators.py", line 575, in 
build_set
    fields = [table[k] for k in self.fieldnames]
  File 
"/home/andre/Dropbox/Projetos/web2py/gluon/packages/dal/pydal/objects.py", line 
510, in __getitem__
    raise KeyError(key)
KeyError: 'servico'

Thanks in advance for any supporting

Best regards

Morganti


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to