There are many ways to do this and your way is not wrong in my POV. You could have used table inheritance see: http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Table-inheritance
If you want for some reason to have all uploaded files references in one table you can do ONE table like C or D that you call "C" and create two tables A_files and B_files that just map records of "C" into A and into B respectively. So you will have 5 tables in total... Else you want to keep the number of tables to 3 you can add a field to table C that contains also the tablename of the record is referring too, this could be as fast as the above if using indexes, but you cannot define a specific reference field to table A (or B) as you do currently. Else you can create table C with two columns one referring to A and the other referring to B... this is going too look ugly if you have many tables to refer too... 2015-01-30 16:15 GMT+01:00 António Ramos <ramstei...@gmail.com>: > Hello > i have an app with table A and B > > Each record in A and B can have many upload files so i created table C and > D respectively just to collect upload files from A and B > > This is my table C and D (they are equal) > > db.define_table('C_files', > Field('f_emp_ref', db.A, notnull=True, writable=False, > readable=False), > Field('f_titulo', type='string', label=T('Categoria'), > notnull=False), > Field('f_doc', type='upload', autodelete=True,notnull=False, > label=T('Documentos'), > represent=lambda x, row:x and > A('%s'%(db.e_docs.f_doc.retrieve(x)[0]), > > _href=URL('default','viewer.html',args=x), > _target="_blank", > _title=T("open file"), > _class='file-reference') > or ''), > ) > > db.define_table('D_files', > Field('f_emp_ref', db.B, notnull=True, writable=False, > readable=False), > Field('f_titulo', type='string', label=T('Categoria'), > notnull=False), > Field('f_doc', type='upload', autodelete=True,notnull=False, > label=T('Documentos'), > represent=lambda x, row:x and > A('%s'%(db.e_docs.f_doc.retrieve(x)[0]), > > _href=URL('default','viewer.html',args=x), > _target="_blank", > _title=T("open file"), > _class='file-reference') > or ''), > ) > > After that i realized that this looks stupid and i would like to short it > as possible. > > > How can i have just table C to collect upload files from table A and B ? > > Thank you > António > > -- > 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.