Add storage location field to battery with dynamic dropdown
Dropdown populated from existing distinct storage locations, with 'New location...' option revealing a text input.
This commit is contained in:
@@ -86,7 +86,13 @@ def create_app(config_object="config"):
|
||||
battery = db.get(Battery, battery_id)
|
||||
if battery is None:
|
||||
abort(404)
|
||||
return render_template("battery_detail.html", battery=battery)
|
||||
storage_locations = [
|
||||
r[0] for r in db.query(Battery.storage_location)
|
||||
.filter(Battery.storage_location.isnot(None))
|
||||
.distinct().order_by(Battery.storage_location).all()
|
||||
]
|
||||
return render_template("battery_detail.html", battery=battery,
|
||||
storage_locations=storage_locations)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Battery — edit notes
|
||||
@@ -114,6 +120,7 @@ def create_app(config_object="config"):
|
||||
battery.tested_date = f.get("tested_date", "").strip() or None
|
||||
battery.charge_cycles = _int("charge_cycles")
|
||||
battery.purchase_date = f.get("purchase_date", "").strip() or None
|
||||
battery.storage_location = f.get("storage_location", "").strip() or None
|
||||
|
||||
db.commit()
|
||||
flash("Details updated.", "success")
|
||||
|
||||
Reference in New Issue
Block a user