On Thursday, June 11, 2020 at 8:55:16 AM UTC-7, mostwanted wrote: > > I have 2 tables one table references the other table. > db.define_table('store_registration', > Field('first_name', requires=IS_NOT_EMPTY()), > Field('last_name', requires=IS_NOT_EMPTY()), > Field('contact_number', label=SPAN('Cell Number'), > requires=IS_NOT_EMPTY()), > Field('id_number', requires=IS_NOT_EMPTY()), > Field('program', requires=IS_NOT_EMPTY()), > Field('level_is', label=SPAN('Level'), requires= > IS_NOT_EMPTY()), > Field('module_is', label=SPAN('Module'), requires= > IS_NOT_EMPTY()), > Field('branch', label=SPAN('Branch'), requires= > IS_NOT_EMPTY()), > Field('residential_place', label=SPAN('Residence'), > requires=IS_NOT_EMPTY()), > Field('region', 'reference auth_group', default=get_group > (), writable=False), #*Here* > Field('recorded_by', 'reference auth_user', default=auth. > user_id, writable=False), > format="%(first_name)s %(last_name)s" > ) > > db.define_table('temperatures', > Field('employee', 'reference store_registration', writable > =False), > Field('branch', 'reference store_registration', writable= > False), > Field('temperature', requires=IS_NOT_EMPTY()), > Field('ID_No', 'reference store_registration', writable= > False), > Field('Cell_No', 'reference store_registration', writable= > False), > Field('residential', 'reference store_registration', > writable=False)) > > I am trying to have the referenced fields pre-populated with their default > values in a table form so that I don't have to populate them manually like > this: > > def client_details(): > details=db.store_registration(request.args(0, cast=int)) > db.temperatures.employee.default=details.id > db.temperatures.ID_No.default=details.id_number > db.temperatures.Cell_No.default=details.contact_number > db.temperatures.branch.default=details.branch > db.temperatures.residential.default=details.residential_place > form=SQLFORM(db.temperatures) > if form.process().accepted: > response.flash=T('Temp Recorded') > return locals() > > But this gives me an error: > <type 'exceptions.ValueError'> invalid literal for long() with base 10: > > I read somewhere that this occurs because > > *reference fields are intended to store the integer record ID's of the > referenced records, not copies of string fields from referenced records* > *.* > Is there a way I can achieve my above task without causing this error?! > > Regards; > > Mostwanted >
I think you want to use an inner join. <URL:https://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Inner-joins> and to have just one field referencing the other table (a "points_to" field),.. /dps -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/4aed9f72-cdff-4029-955b-99509864c315o%40googlegroups.com.