Hello again!
After some reading about SQLForm, obviously that's what I need. But since
there are some different options I would like to choose the correct one.
For my case, should I use a SQLForm.grid or a SQLForm.factory()? And in the
case of using a grid, is it posible to have a select list (something like a
drop-down list) for each row or I have to use the "Update" button for each
one?
Kind regards!
On Friday, October 18, 2013 10:28:47 PM UTC+2, Wonton wrote:
>
> Thank you very much Tim!!
>
> I didn't even consider this posibility. It seems that it's what I was
> looking for. I will try it.
>
> Kind regards!
>
> On Friday, October 18, 2013 3:56:43 AM UTC+2, Tim Richardson wrote:
>>
>> You are doing this the really hard way, I think.
>> If you read the book a bit more you will discover web2py's built-in forms.
>> Probably you should use SQLFORM.
>> This means you do all the coding in the controller. Behind the scenes,
>> SQLFORM will create a variable which contains the HTML to display the form,
>> and it also includes the logic to update the database table.
>>
>> While you are developing, you can rely on the "developer" or generic
>> views, which means you don't even need to worry about making a view until
>> you are ready.
>>
>> In other words, you can do all of this in one line (in the controller)
>>
>> form = SQLFORM(db.matches)
>>
>> (assuming you have setup up your table definition well).
>>
>>
>> Or you should read about SQLFORM.grid, which may be more what you want.
>> It starts by displaying all the records in a table, and then lets the user
>> choose which rows to edit. It then automatically generates an SQLFORM for
>> that row. Still only one line :)
>>
>>
>>
>>
>>
>>
>> On Friday, 18 October 2013 10:22:40 UTC+11, Wonton wrote:
>>>
>>> Hello,
>>>
>>> I've been working with web2py controllers to connect with my database
>>> and I haven't use views so far, so I don't know if what I'm trying to do is
>>> very wrong. In that case, please, tell me ;-).
>>>
>>> Suppose I have this:
>>>
>>> controllers/mycontroller.py:
>>>
>>> def show_matches():
>>> matches = db(db.matches.id > 0).select()
>>> return dict(matches=matches)
>>>
>>> views/show_matches.html:
>>>
>>> {{extend 'layout.html'}}
>>> <h1>MATCHES</h1>
>>> <table>
>>> <th>
>>> <th>MATCH</th>
>>> <th>TEAM1</th>
>>> <th>TEAM2</th>
>>> </th>
>>> {{for match in matches:}}
>>> <tr>
>>> <td>{{=match['team1']}} vs. {{=match['team2']}}</td>
>>> <td>
>>> <forms>
>>> <select style="width:80px;">
>>> <option>0</option>
>>> <option>1</option>
>>> <option>2</option>
>>> <option>+2</option>
>>> </select>
>>> </form>
>>> </td>
>>> <td>
>>> <forms>
>>> <select style="width:80px;">
>>> <option>0</option>
>>> <option>1</option>
>>> <option>2</option>
>>> <option>+2</option>
>>> </select>
>>> </form>
>>> </td>
>>> </tr>
>>> {{pass}}
>>> </table>
>>>
>>>
>>> I would like to include a button (with 'a' and 'onclick' I guess) at the
>>> bottom of the page so when the user clicks in it, all data selected in the
>>> forms are sent to mycontroller.py (to store_results_in_ddbb function).
>>>
>>> How could I read all this data and send it to a controller? Should I
>>> have only one <form> and all <select> components pointing to it through a
>>> 'form' tag? Should I have all select components with an 'id' tag and read
>>> the data through this tag?
>>>
>>> I'm a newbie with HTML (web frontend in general) so I hope I am not
>>> saying something very stupid ;-).
>>>
>>> Any idea will be very appreciated.
>>>
>>> Thank you very much and kind regards!
>>>
>>>
--
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/groups/opt_out.