Here is what I would do. def manage_employees(): company_id = 1 employees_for_company1 = db().select(db.employees.company_id == company_id) if request(0) == 'new': db.employees.company_id.default = company_id db.employees.company_id.writable = False db.employees.company_id.readable = False
grid = SQLFORM.grid(employees_for_company1) On Wed, Jan 29, 2014 at 3:24 PM, A36_Marty <ma...@mccaslandcorp.com> wrote: > Thanks for your reply. Might be the clearest to respond with code: > > <Models> > > db.define_table('company', > Field('name','string' )) > > db.define_table('employees', > Field('company_id', db.company), > Field('name', 'string')) > > <Controller> > > def manage_employees(): > employees_for_company1 = db().select(db.employees.company_id == 1) > grid = SQLFORM.grid(employees_for_company1) > > > My question is when I press "ADD" on the grid, I get a new screen in which > "company_id" is visible and blank. How would I customize the "add" form > created by the grid to 1) not show the company_id field yet also fill it in > with "1" before the insert to make sure the newly added employee is related > to the currently viewed company - company_id "1" in this case? > > Many thanks for your help. > > > > On Wednesday, January 29, 2014 1:58:46 PM UTC-6, Jim S wrote: >> >> So, do you want to modify the layout of the add/edit forms, or just >> default in the COMPANY on an add? >> >> this line: I see formargs, editargs, createargs, etc., but am having >> trouble finding examples (that I understand) of how to modify these forms >> and not recreate the wheel by making totally custom add/edit grid forms. >> >> ....makes me think you don't want to alter the layout. Looking for >> clarification. >> >> -Jim >> >> On Wednesday, January 29, 2014 11:13:27 AM UTC-6, A36_Marty wrote: >>> >>> >>> I've created a web2py grid of records based on the selection on the >>> page. i.e. a table COMPANY has many EMPLOYEES -- someone selects a given >>> COMPANY and a SQLFORM.grid of the related EMPLOYEES is shown. >>> >>> Question: How can I customize the web2py Add/Edit forms that appear >>> when the respective buttons are pushed on the Grid. >>> >>> More specifically, if one wishes to add an EMPLOYEE, I need to hide the >>> related COMPANY field on the add form, yet still fill in the value with >>> whatever COMPANY is currently selected. >>> >>> I see formargs, editargs, createargs, etc., but am having trouble >>> finding examples (that I understand) of how to modify these forms and not >>> recreate the wheel by making totally custom add/edit grid forms. >>> >>> Your responses are most appreciated. I am a novice web2py user with >>> limited webapp development experience. >>> >>> Thanks in advance. >>> >> -- > 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 a topic in the > Google Groups "web2py-users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/web2py/n9uinYLDFZ4/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > web2py+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > -- 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/groups/opt_out.