True, readonly forms do not show virtual fields. Perhaps submit a Google Code issue requesting that feature.
Anthony On Wednesday, July 23, 2014 12:44:30 PM UTC-4, Adam Filić wrote: > > Yes, you are right. That was the problem and it shows up in the grid now, > but I can't see it in the view form. All included fields are readable. > Thank you > > > 2014-07-23 17:53 GMT+02:00 Anthony <[email protected]>: > >> I think the problem is that your virtual field depends on some fields you >> have not included in your grid, so the virtual field values cannot be >> calculated. Instead of specifying the "fields" argument, you can hide >> particular fields from the grid by setting their "readable" attribute to >> False. In that case, all the fields will be included in the query done by >> the grid, which will enable the virtual field values to be calculated. >> >> Anthony >> >> >> On Wednesday, July 23, 2014 10:41:54 AM UTC-4, Adam Filić wrote: >>> >>> One year later I still can't display virtual field in the SQLFORM.grid >>> with an error: >>> <type 'exceptions.AttributeError'> 'Row' object has no attribute 'broj' >>> And my virtual field is defined as: >>> >>> db.define_table('fin_fis', >>> Field('god','integer',label=T('Year')), >>> Field('pod','reference sif_pod',label=T('Company'),writable=False, >>> readable=False), >>> Field('oj','reference sif_oj',label=T('Department')), >>> Field('kasa','integer',label=T('Billing device')), >>> Field('vd','reference sif_vd',label=T('Document type')), >>> Field('br','integer',label=T('Number')), >>> Field.Virtual('broj',lambda row: '%05d/P%03d%03d/%d'%(row.fin_ >>> fis.br,row.fin_fis.oj,row.fin_fis.vd,row.fin_fis.kasa),label='Broj'), >>> ..... >>> ) >>> >>> This is my field list: >>> fields = (db.fin_fis.oj,db.fin_fis.kasa,db.fin_fis.br,db.fin_fis. >>> broj,db.fin_fis.dvi,db.fin_fis.iznrac,db.fin_fis.npl,db.sif_radnici.ime, >>> db.sif_radnici.prezime) >>> >>> I'm using: 2.9.5-stable+timestamp.2014.03.16.02.35.39 (Running on >>> Apache/2.4.9 (Ubuntu), Python 2.7.3) >>> >>> >>> Dana subota, 20. srpnja 2013. 11:54:24 UTC+2, korisnik peckto napisao je: >>>> >>>> I think i can explain this behaviour. >>>> The statement "var in list" cals the lists __contains__ method, >>>> which loops through the list and compares each element with var. >>>> But in case of an Field object the equals operator (__eq__) has another >>>> meaning, >>>> it's the "WHERE" part of the db query: >>>> db(db.table.id==1).select() >>>> So this comparison will olways return True. >>>> >>>> >>>> Am Samstag, 20. Juli 2013 09:00:52 UTC+2 schrieb Massimo Di Pierro: >>>>> >>>>> Strange. Ok. I changed it again. Can you please check it. I am still >>>>> trying to avoid the double loop for every virtual table. >>>>> >>>>> On Friday, 19 July 2013 16:54:05 UTC-5, peckto wrote: >>>>>> >>>>>> Regarding your changes: >>>>>> + all_fields = filter(lambda nv: nv[1] in fields and >>>>>> + isinstance(nv[1],(FieldVirtual, >>>>>> FieldMethod)), >>>>>> + table.iteritems()) >>>>>> It doesn't work. It ends up in returning all virtual fields, even >>>>>> when they are not requested. >>>>>> It's because of the "var in list" statement: >>>>>> nv[1] in fields >>>>>> always returns True. I don't know why. >>>>>> >>>>>> Another solution would be to use the id() function: >>>>>> id(nv[1]) in [id(f_) for f_ in fields] >>>>>> but you have overwritten this function >>>>>> 2091: id = value >>>>>> >>>>>> So I came finally to the complicated looking statement: >>>>>> nv[0] in [f_.name for f_ in fields] and nv[1].tablename == tablename >>>>>> >>>>>> Maybe you can tell me why the "var in list" statement fails >>>>>> or we use one of the other solutions (while renaming the id value). >>>>>> >>>>> -- >> 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 a topic in the >> Google Groups "web2py-users" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/web2py/yIRGzpZYcbg/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> [email protected]. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Srdačan pozdrav > > Adam Filić > > www.tt-program.com > -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.

