Hey Dave thanks for replying. I think i'm going about this the wrong way.
The *temperature *table already references the *store_registration *table
via the *employee *variable. By my understanding the *employee *variable
already holds all the information in the *store_registration *table & I
need some values from the *store_registration table(contact_number,
id_number, branch, residential_place)* to be unpacked & stored with the new
details (temperature) in the *temperature *table without me having to
re-enter them again, isnt there a way for this?
I have been looking at the inner-joins I just dont get how I can apply them
here, a small example with regards to issue would go a long way.
Thank you 😊
On Friday, June 12, 2020 at 9:49:04 AM UTC+2, Dave S wrote:
>
>
>
> 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/ac3f13d6-3b3c-4fcd-96de-60172eded4bao%40googlegroups.com.