Thanks!

I got it like this :

db.atable.othertablefield_id.represent=\
     lambda value: "%(num)s" % (db.v_othertable_num[value] or {'num':'unkown'})


;-)

Jonhy


On 2010-07-29 18:18, mdipierro wrote:
please try:

db.atable.othertablefield_id.represent=\
      lambda value: "%(num)s" % (db.v_othertable_num[value] or
{'num','unkown'}

(this will fix if the problem is that record is None)
and/or

db.atable.othertablefield_id.represent=\
      lambda value: str(db.v_othertable_num[value].num)

(this will fix it if it is a type conversion problem)


On Jul 29, 4:55 pm, Jean-Guy<jean...@gmail.com>  wrote:
>  Hello,
>
>  I define the way to show the id field in crud.read like this :
>
>  db.atable.othertablefield_id.represent=\
>        lambda value: "%(num)s" %db.v_othertable_num[value]
>
>  Placed in model.
>
>  v_othertable_num is a database view of the related table because the
>  number are formed of many fields so I concatenated them into a unique
>  number with the view.
>
>  The problem is I have a unnormalized table in wich differents id fields
>  as to be (represented), but most of the time only one of them are
>  entered. The app break when crud.read return "None" because a field have
>  been let blank at the seizure. Here is the error :
>
>  Traceback(most recent call last):
>      File"/version_181-4/web2py/gluon/restricted.py",line178,inrestricted
>        execccodeinenvironment
>      
File"/version_181-4/web2py/applications/app/controllers/default.py"</admin/default/edit/GUImdg1/controllers/lotns.py>,line83,in<module>
>      File"/version_181-4/web2py/gluon/globals.py",line96,in<lambda>
>        self._caller=lambdaf:f()
>      File"/version_181-4/web2py/gluon/tools.py",line2192,inf
>        returnaction(*a, **b)
>      
File"/version_181-4/web2py/applications/app/controllers/default.py"</admin/default/edit/GUImdg1/controllers/lotns.py>,line36,inread
>        request.args[1])
>      File"/version_181-4/web2py/gluon/tools.py",line2797,inread
>        formstyle=self.settings.formstyle
>      File"/version_181-4/web2py/gluon/sqlhtml.py",line687,in__init__
>        inp=field.represent(default)
>      
File"/version_181-4/web2py/applications/app/models/default.py"</admin/default/edit/GUImdg1/models/lotns.py>,line224,in<lambda>
>        lambdavalue:"%(num)s"%db.v_othertable_num[value]
>  TypeError:format requires a mapping
>
>  I used postgres as dbms backend with postgres sequence formatting style
>  (table_field_id_seq)...
>
>  I am not sure what the origin of the error... I don't know how to verify
>  if field are returning None...
>
>  Jonhy

Reply via email to