I made the changes and switched to using {{=form}}, but It's still creating
a new record. I just realized I didn't post a part of the view that might
be causing the issue. I have multiple forms on a single page.
...
{{=for row in rows:}}
{{=form}}
{{pass}}
...
Could that be causing the issue? I went ahead and uploaded what I have to
Python Anywhere to help illustrate what I'm trying to do. You can check it
out here
<https://drewhowell.pythonanywhere.com/TwoFiveTracker/default/workouts> (the
layout is slightly broken because of the vertical radio buttons, but that
will be fixed next).
On Saturday, August 9, 2014 10:33:02 PM UTC-4, Massimo Di Pierro wrote:
>
> One problem is that you want to select after you process the form:
>
> def workouts():
> r = db.workouts(request.args(0))
> form = SQLFORM(db.workouts, r).process()
>
> if form.accepted:
> response.flash = 'form accepted'
> elif form.errors:
> response.flash = 'form has errors'
>
> rows = db(db.workouts).select()
> return locals()
>
> Also instead of using a custom form (unless you really need one), I
> suggest you do {{=form}} in view and
>
> make the fields that you do not need in the form Field(...,
> readable=False, writable=False)
>
> On Saturday, 9 August 2014 20:01:51 UTC-5, Drew Howell wrote:
>>
>> I'm new to Web2Py, so I am creating a (what I thought was a) simple app
>> that tracks progress of a workout routine. I have a database (db.workouts)
>> that has information such as Workout Name, Rating, Completed, etc. I have 2
>> fields(rating, completed) I would like to update via a form. I have tried a
>> couple different methods, but can't seem to get anything to work correctly.
>> The other fields are already entered in the table and should not be changed.
>>
>> "Rating" should be updated by a set of radio buttons and "Completed"
>> should be set to 0 when the form is submitted (0=complete, 1=current,
>> 2=locked). I have created the form, but have done something wrong because,
>> when it is submitted, a new record is created rather than updating the
>> existing one.
>>
>> *Here is my code:*
>>
>> *Model:*
>>
>> db.define_table('workouts',
>> Field('stage'),
>> Field('w', type="integer"),
>> Field('workout'),
>> Field('complete', type="integer"),
>> Field('d', type="integer"),
>> Field('rating', requires=IS_IN_SET([1, 2, 3, 4 ]),
>> widget=SQLFORM.widgets.radio.widget),
>> auth.signature
>> )
>>
>> *Controller:*
>>
>> def workouts():
>> rows = db(db.workouts).select()
>>
>> r = db.workouts(request.args(0))
>> form = SQLFORM(db.workouts, r)
>>
>> if form.process().accepted:
>> response.flash = 'form accepted'
>> elif form.errors:
>> response.flash = 'form has errors'
>>
>> return locals()
>>
>> *View:*
>>
>> ...
>>
>> {{=form.custom.begin}}
>> {{=form.custom.widget.rating}}
>> {{=form.custom.submit}}
>> {{=form.custom.end}}
>>
>> ...
>>
>>
>> As I mentioned earlier, I am new and I may be going about this completely
>> the wrong way. So any help would be greatly appreciated. I can provide more
>> information if needed. Thanks.
>>
>
--
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.