I'm coding my first GAE web app in Python. I need to collect ~30 properties and instantiate a Client object (I'm using Model.db). I'd like to accomplish this on 4 separate sequential forms. If I use a separate page handler for each form, what is the best way to extract and reference the key or id on each form and put data into the same data entity? How do I avoid a global variable?
Asked
Active
Viewed 40 times
1 Answers
0
Not sure I follow... You may need to explain the issue a little more clearly.
First, do not use a global variable.
You can have 4 forms on the same template, all with the same handler. Give each a separate hidden attribute. Or, depending on your templating package, you should be able to access the form by ID.
In your handler:
entity = MyModel.get_by_key_name('my_key_name')
if request.method == 'POST':
if request.POST['hidden_field'] == 'firstform':
entity['prop_1'] = form.prop_1.data
...
if request.POST['hidden_field'] == 'secondform':
...
...
entity.put()
else:
return <template>
You will need to modify the syntax above to suit your templating pkg.

GAEfan
- 11,244
- 2
- 17
- 33
-
@GAEfanThis bit of guidance has been a big help! I'm moving forward. I've crossed another hurdle when I post inside the same handler. I just posted a [new question](http://stackoverflow.com/questions/23051746/how-to-pass-variables-between-methods-in-the-same-class-in-python) to elaborate further. – bholben Apr 14 '14 at 04:05