If I do this inside the action "create_table" 

 db.Project.insert( added_term = ('English: 0 to 6 years', 'Math: 0 to 2 
years', 'History', 'over 5 years','science: never tought'))

It works. But how to save a list like this inside the controller every time 
someone hits "add" button? I am wondering if I have to save the variable in 
a temp table and read it. Because every time I hit the "create_table" 
action, all the variable gets reinitialize. 

Calling for Anthony with all his knowledge to help me with this! lol.

Happy memorial day everyone. 

Cheers,


On Friday, May 27, 2016 at 5:22:16 PM UTC-4, Ron Chatterjee wrote:
>
> Running into some issues and hoping community help out with thoughts. How 
> do I append to list:string and using form inside a form (custom form). 
>
> Question: How do I append skill_and_experience  as a list:string into the 
> field added_term as 'English': '1 year', 'Math':'2 years',...etc. 
>
> May be there is a better way to do this, but this is how I started out 
> with. 
>
>
> *Model.py:*
>
> db.define_table( 'Experience',Field('Experience_level'), format = 
> '%(Experience_level)s')
> db.define_table( 'teaching',Field('teach_string'), format = 
> '%(teach_string)s')
>
>
> db.define_table( 'add_list_item',
>                 Field('skill_list', db.teaching, label='Enter Your Skills 
> sets', comment = 'Enter skills'),
>                 Field('Experience_list', db.Experience, label='Enter Your 
> Experience',  comment = 'Enter years'))
>                 
>
> db.define_table( 'Project', 
>                 Field("Title", "string", 
> requires=IS_NOT_EMPTY(),default=None),
>                 Field("added_term", "list:string", 
> requires=IS_NOT_EMPTY()),)
>
>
>
> *Controller:*
> def create_table():
>     a_list = 'My skills and experience:'
>     skill_and_experience = [];
>  
>     form1 = SQLFORM(db.Project)
>     form2 = SQLFORM(db.add_list_item, submit_button=' + Add',).process()
>     form2.element('input[type=submit]').update(_class='btn btn-custom')
>     
>     if form2.accepted:
>         a = db(db.add_list_item.id == form2.vars.id).select().first()
>         skills = db(db.teaching.id == a.skill_list).select().first()
>         experience = db(db.Experience.id == 
> a.Experience_list).select().first()
>         skill_and_experience = skills.teach_string+':' +''+ 
> experience.Experience_level
>         added_term.append(skill_and_experience)
>         response.flash = T("Added Experience")
>     
>     if form1.accepted:
>         response.flash = T("success!")
>         
>     return dict(form1 = form1, form2 = form2, a_list = a_list)
>
>
> *View:*
>
> {{extend 'layout.html'}}
>
> <center>
>
> {{=form1.custom.begin}}
>
>
> <div class="input-title">
>     {{=form1.custom.widget.Title}}
>      <br>
>     
> {{=form2.custom.begin}}    
>
> <h4>{{=a_list}}</h4>
>
>
>
> <table>
> <thead>
>   <tr>
>      <div class="skill_list"> 
>  
>   <td> {{=form2.custom.widget.skill_list}}   </td>
>           <div class="exp_list"> 
>     <td>{{=form2.custom.widget.Experience_list}}   </td>    
>               
>                 <div class="add_button"> 
>               <td> {{=form2.custom.submit}} </td>   
>       
> </tr>
> </thead>
> </table> 
> <br>
> <br>
> {{=form2.custom.end}}
>       
>  {{=form1.custom.submit}}
>     
>     
>         </div> 
>       </div>
>       </div>  
>    </div> 
> {{=form1.custom.end}}
> </center>
>
> <style>
> .input-title{
>     height: 100px;
>     width: 400px;
> }
>
> #add_list_item_skill_list{
>      width: 200px;
> } 
> #add_list_item_Experience_list{
>      width: 200px;
> } 
>
>
> .btn-custom { text-align:right;color: blue;width:50px; 
> padding:20%;position: relative;top: -4px;left: 4px;height 20px;}   
> </style>
>
>
>
> The idea is to basically add experience and training using form2 and add 
> that to form1 and then process both. But I am having problem in appending 
> data into list:string like I would for project. 
>
> Project.id 
> <http://127.0.0.1:8000/test_two/appadmin/select/db?orderby=Project2.id>
> Project.Title2 
> <http://127.0.0.1:8000/test_two/appadmin/select/db?orderby=Project2.Title2>
> Project.added_term2 
> <http://127.0.0.1:8000/test_two/appadmin/select/db?orderby=Project2.added_term2>
> 1 <http://127.0.0.1:8000/test_two/appadmin/update/db/Project2/1> test1 
> test1
> 2 <http://127.0.0.1:8000/test_two/appadmin/update/db/Project2/2> test2 test1, 
> test2, test3
> 3 <http://127.0.0.1:8000/test_two/appadmin/update/db/Project2/3> test3 
> test23, 
> test32
>

-- 
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].
For more options, visit https://groups.google.com/d/optout.

Reply via email to