tutorial 2, adding new lists/tables via form/client

master
grgr 2 years ago
parent 9aa6f5ca0b
commit 2ff60e02e9

Binary file not shown.

@ -44,6 +44,17 @@ def create():
content = request.form['content']
list_title = request.form['list']
# --- create the new lists here as well ---
new_list = request.form['new_list']
# if a new title (list) is submitted add it to the database
if list_title == 'New List' and new_list:
conn.execute('INSERT INTO lists (title) VALUES (?)',
(new_list,))
conn.commit()
#update list_title to refer to the newly added list
list_title = new_list
if not content:
flash('Content is required!')
return redirect(url_for('index'))

Binary file not shown.

@ -14,6 +14,7 @@
<div class="form-group">
<label for="list">List</label>
<select class="form-control" name="list">
<option value="New List" selected>New List</option>
{% for list in lists %}
{% if list['title'] == request.form['list'] %}
<option value="{{ request.form['list'] }}" selected>
@ -27,6 +28,14 @@
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="new_list">New List</label>
<input type="text" name="new_list"
placeholder="New list name" class="form-control"
value="{{ request.form['new_list'] }}"></input>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
</div>

Loading…
Cancel
Save