smart grid

39 views
Skip to first unread message

T.R.Rajkumar

unread,
Jul 17, 2020, 7:49:19 AM7/17/20
to web2py-users
db.define_table('pm_events',
                Field('eqp_id', 'reference pm_equip'),
                Field('lc_no', 'reference dblc.lc_vw_lc_master.lc_no'),               
                Field('pending_work', type='string'),
                Field('remarks', type='string'),
                Field('completed', type='string', length=1,required='True',notnull='True'),
                Field('update_uid','string',length=6,required='True',notnull='True',default = session.uname),
                Field('update_dt','datetime',required='True',notnull='True',default=request.now)
)


dblc.define_table('lc_vw_lc_master',
                Field('lc_no', type='string',length=11,required='True',notnull='True'),
                Field('unit_descr',type='string'),
                Field('btg_descr',type='string'),
                Field('sys_descr',type='string'),
                Field('eqp_descr',type='string'),
                Field('lc_from',type='datetime'),
                Field('lc_to',type='datetime'),
                Field('work_descr',type='string'),
                Field('lc_req_uname',type='string', length=11),
                Field('lc_statue',type='string'),
                Field('lc_req_dt',type='datetime'),
                Field('lc_issue_uname',type='string', length=11),
                Field('lc_issue_dt',type='datetime'),
                primarykey=['lc_no'],
                migrate=False)

db.define_table('pm_equip',
                Field('equipment_id', 'integer'),
                Field('equipment_no', 'string', length = 25),
                Field('equipment_detail','string'),
                Field('division_id', 'integer'),
                Field('location_id', 'reference pm_location'),
                Field('subdivision_id', 'integer'),
                Field('divn', 'string',length = 10),
                Field('rep_code', 'string', length = 10)
               )
db.define_table('pm_location',
                Field('location_id', 'integer'),
                Field('location_name', 'string')
                )

I have the above tables in db.py
Now in controller pm_events.py I want to have a form for pm_events which has reference to pm_equip which in turn has reference to pm_location.
In the create form for pm_events on the selection of equipment it should show the location of the equipment and user enters other details and submits the form.
How to achieve this functionality, may be in a smart grid.
Thank you for the time.

AGRogers

unread,
Jul 17, 2020, 11:00:58 AM7/17/20
to web...@googlegroups.com
One option would be to set the Format of the Equipment record to also include the location - eg 'My Equipment (It's Location)'

Then your selection drop down list should include the location. 

--
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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/2f1ae9c8-a967-443f-b0f4-197ab4f869e3o%40googlegroups.com.

villas

unread,
Jul 17, 2020, 11:11:10 AM7/17/20
to web2py-users
It seems that you are using two DBs (db and dblc). 
In my experience,  you cannot make relationships across two distinct DBs.

Suggestion:

1. Create a set of all the lc_vw_lc_master.lc_no possibilities
2. Create a normal string field for pm_events.lc_no with a IS_IN_SET validator.

If the record set for 1. is large, you can cache it.

T.R.Rajkumar

unread,
Jul 18, 2020, 1:33:33 AM7/18/20
to web2py-users
Thank you AGRogers
As you said the equipment record format to include the location, that would do for me.
Can you please tell how to do that.


T.R.Rajkumar

unread,
Jul 18, 2020, 4:32:18 AM7/18/20
to web2py-users
Thank you villas.
The dblc I am using a view and referencing that views lc_no in my table pm_events. I shall try how it works and if not I will go as you said.

AGRogers

unread,
Jul 18, 2020, 5:47:32 AM7/18/20
to web...@googlegroups.com
This is how i do something similar in one of my tables:

db.define_table('OrganisationUser', 
Field(.....),
format = lambda r: ("%s [%s]") % (db.auth_user(r.UserID).DisplayName, db.Organisation(r.OrganisationID).ShortName)
)

For you maybe:

db.define_table('pm_equip',
  Field(.....) .....
  format = lambda r: ("%s [$s]") % (r.equipment_detail, db.pm_location(r.location_id).location_name)
)



--
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+un...@googlegroups.com.

T.R.Rajkumar

unread,
Jul 18, 2020, 8:35:27 AM7/18/20
to web2py-users
Thank you AGRogers. It works.

AGRogers

unread,
Jul 18, 2020, 10:01:39 AM7/18/20
to web...@googlegroups.com
Great

On Sat, 18 Jul 2020 at 22:35, T.R.Rajkumar <t.r.raj...@gmail.com> wrote:
Thank you AGRogers. It works.

--
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+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages