My first app almost done. Question about input forms with "cross" references

1 view
Skip to first unread message

Offray Vladimir Luna Cárdenas

unread,
Jun 1, 2009, 9:29:56 AM6/1/09
to web...@googlegroups.com
Hi all,

My first Web2py app is almost done and with this framework I can even
take a break and still being productive and nos slaved by development
:-) (and I'm not a developers so is great to see how web2py brings
development to common folks). Now I want to create a richer input form
using rows which information is gathered from two different tables, but
still I'm not there. I have created a helper SQLObjects for cross
references between tables. You can see the complete model here:

http://offray.tiddlyspot.com/#Web2pySolucionarioModelo

but the important new parts are this

[1] fuentes_autor=(db.fuentes.autor_id==db.autor.id)
[2]
fuentes_ediciones=((db.ediciones.fuente_id==db.fuentes.id)&(db.fuentes.autor_id==db.autor.id))

[1] gives information about authors and sources and [2] adds information
about different editions of the same sources (for example two students
can be solving exercises from two different editions of the same book).

The editions table is related with the sources one. Here is each one:

(sources/fuentes):
db.define_table('fuentes',
SQLField('autor_id',db.autor),
SQLField('titulo','string',length=128),
SQLField('url_web','string'),
SQLField('tema_id',db.temas))

(editions/ediciones):
db.define_table('ediciones',
SQLField('fuente_id',db.fuentes),
SQLField('fecha','string'),
SQLField('edicion','string'))

This are two conditions for the form to add editions:

db.ediciones.fecha.requires=IS_NOT_EMPTY()
[3]
db.ediciones.fuente_id.requires=IS_IN_DB(db,'fuentes.id','fuentes.titulo')

But with the second one I only get the title of the source and I would
like the Title and the Author, which is in another table. I tried with
the helper SQLObject [1] replacing [3] with:

db.ediciones.fuente_id.requires=IS_IN_DB(db(fuentes_autor),'db(fuentes_autor).select(db.fuentes.id)','%(db(fuentes_autor).select(db.fuentes.titulo))s
%(db(fuentes_autor).select(db.autor.apellido))s')

But I get the error message:

File "/home/offray/Programas/Web2py/1.62.3/applications/solucionario/models/db.py" <http://127.0.0.1:8000/admin/default/edit/solucionario/models/db.py>, line 85, in <module>
db.ediciones.fuente_id.requires=IS_IN_DB(db(fuentes_autor),'db(fuentes_autor).select(db.fuentes.id)','%(db(fuentes_autor).select(db.fuentes.titulo))s %(db(fuentes_autor).select(db.autor.apellido))s')
File "/home/offray/Programas/Web2py/1.62.3/gluon/validators.py", line 214, in __init__
(ktable, kfield) = str(self.field).split('.')
ValueError: too many values to unpack


So, I think that I'm almost done trying to use helper SQLObjects to make
a better input form, but I'm missing something. Any help would be
appreciated.

Cheers,

Offray

Ps: If I solved this soon, tonight I will try to publish this first app
to the world (well basically my students, but open to anyone). This will
be the first of many Web2py apps, some of them pretty more complex. So I
can not be grateful enough, but you have a new "evangelist" for Spanish
speakers and Iberoamerica :-P

Reply all
Reply to author
Forward
0 new messages