Try print/log the value of r in your code. Perhaps do a {{=r}} and see if
there record you are trying to edit is there.
On Sunday, 10 August 2014 15:57:02 UTC-5, Drew Howell wrote:
>
> It's still creating a new record rather than updating. So I've still got
> something wrong. I need to look over the code and see if I can find
> anything that sticks out.
>
> On Sunday, August 10, 2014 4:07:57 PM UTC-4, Massimo Di Pierro wrote:
>>
>> I agree that you only seem to need one form. If this is the case there
>> should not be problems. Can you confirm?
>>
>> Massimo
>>
>> On Sunday, 10 August 2014 12:58:06 UTC-5, Drew Howell wrote:
>>>
>>> The purpose of the app/page is to track progress of a workout routine.
>>> It is a 5 week / 35 day schedule. I have all the "static" information
>>> stored in the table (Day, Week, Workout Name), but there are 2 other fields
>>> in the table that would need to be updated: "rating" which is where you
>>> rate your performance (1-4) entered via radio buttons, and "completed"
>>> which can be either 0, 1, or 2 (0=complete, 1=current, 2=locked) and is
>>> automatically changed to 0 when the form is submitted.
>>>
>>> I am generating the page by iterating through the records in the table
>>> and displaying them (see here for example
>>> <https://drewhowell.pythonanywhere.com/TwoFiveTracker/default/workouts.html>).
>>>
>>> I realize now that I really only need 1 form, which is for the current day.
>>> The user will select a radio button and click submit. It should then update
>>> the "rating" field as well as the "completed" field. After the form is
>>> submitted the page is generated again, but the next day will be the
>>> "current" day with the form. I apologize if that's confusing, but the best
>>> way to understand it is looking at the example
>>> <https://drewhowell.pythonanywhere.com/TwoFiveTracker/default/workouts.html>
>>> .
>>>
>>> This is what I'm doing in my workouts.html View:
>>>
>>> {{for row in rows:}}
>>> {{if row.complete == 0:}}
>>> // completed day layout
>>> {{elif row.complete == 1:}}
>>> // current day layout
>>> {{=form}}
>>> {{else:}}
>>> ///locked day layout
>>> {{pass}}
>>> {{pass}}
>>>
>>>
>>> On Sunday, August 10, 2014 1:27:17 PM UTC-4, Massimo Di Pierro wrote:
>>>>
>>>> That's it then. You cannot have multiple forms on the same type on one
>>>> page unless they refer to different tables. There are other ways but it
>>>> really depends on what you are trying to do. Can you explain in words what
>>>> is the page supposed to do.
>>>>
>>>>
>>>> On Sunday, 10 August 2014 11:11:05 UTC-5, Drew Howell wrote:
>>>>>
>>>>> 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.