First you are getting the error because.
db.publicaciones.autores.represent is not defined so it is None and hence
not callable.
That said. Here's a generic represent function you can use with
list:reference fields.
def represent_listref(table, *fields):
def represent(values):
result = []
if values is None:
return None
for value in values:
v = db[table][value]
rendered = {'id': value}
for field in fields:
represent = db[table][field].represent
rendered[field] = represent(v[field]) if represent else v[
field]
result.append(rendered)
return result
return represent
The way to use it is in the model set it as represent
db.define_table('publicaciones',
Field('titulo'),
Field('descripcion', 'text', label='Descripción'),
Field('autores', 'list:reference db.personas',
requires= IS_IN_DB(db, 'personas.id', '%(nombres)s %(apellidos)s',
multiple=True), represent=represent_listref('personas', 'nombres',
'apellidos')),
format='%(titulo)s')
Then in your controller, you need to render the rows.
lista_publicaciones = list(db(db.publicaciones.tipo == tipo).select(orderby
=~ db.publicaciones.fecha).render())
Now in your view for each "publicacione" in autores you will have a list of
dicts with the fields nombres and apellidos as well as the id which my
implementation of represent_listref always adds.
--
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.