add new category

master
grgr 2 years ago
parent aa594ee3ca
commit 8f7f127937

@ -81,6 +81,17 @@ def create():
content=request.form['content'] content=request.form['content']
cat_title=request.form['cat'] cat_title=request.form['cat']
#create a new category:
new_category = request.form['new_category']
# if a new category_title is created add it to the table of categories
if cat_title == 'New category' and new_category:
conn.execute('INSERT INTO categories (title) VALUES (?)',
(new_category,))
conn.commit()
# update cat_title to refer to the newly added category
cat_title = new_category
if not content: if not content:
flash('plz write a content!') flash('plz write a content!')
return redirect(url_for('home')) return redirect(url_for('home'))

Binary file not shown.

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

Loading…
Cancel
Save