In general, Virtual field will try to calculate it's value. It can fail
(for example, you didn't select all the fields that are needed to do the
calculation, or your calculation is buggy). If it fails, it won't be there.

Which database are you using?

I suspect that .count() returns None and thus it fails on +. But it is
backend-specific, I am not sure.

Marin


On Sun, May 4, 2014 at 6:02 AM, Leonardo Pires Felix <
leona...@piresfelix.com> wrote:

>
> I've created a virtualfield on my table as this:
> db.define_table("alunos",
>       SQLField("nome", "string", length=255, label="Nome", notnull=True,
> requires=IS_UPPER())
>       SQLField("data_nascimento", "date", label="Data de
> nascimento",represent=campoDataNascimento, notnull=True),
>       SQLField.Virtual('mediaFreq',lambda linha:
> db(db.entrada_cartao_alunos.id_aluno == 
> linha.aluno.id).count()+db(db.faltas_alunos.id_aluno
> == linha.aluno.id).count())
>       )
>       singular="Aluno",
>       plural="Alunos",
>       format="%(nome)s")
>
> And on the smartgrid the virtual field doesn't show.
>
> I've tried from command line, but:
> Traceback (most recent call last):
>   File "<console>", line 1, in <module>
>   File "/home/leonardo/domains/homo.com/arquivos/web2py/gluon/dal.py",
> line 7343, in __getitem__
>     raise ae
> AttributeError: 'Row' object has no attribute 'mediaFreq'
>
> But on dir(db.alunos) the virtualfield is there, on db.alunos.fields isn't.
> So, the virtualfield isn't working anymore?
>
> --
> 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.
>

-- 
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