From 70abcfd0ac01832f75d98f440f2c36ab7472221b Mon Sep 17 00:00:00 2001 From: Darek Date: Sun, 12 Apr 2026 15:22:02 -0500 Subject: [PATCH] Add storage location field to battery with dynamic dropdown Dropdown populated from existing distinct storage locations, with 'New location...' option revealing a text input. --- app.py | 9 ++++++++- models.py | 1 + templates/battery_detail.html | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index d2f4843..b2272dc 100644 --- a/app.py +++ b/app.py @@ -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") diff --git a/models.py b/models.py index 95110cd..d6c582e 100644 --- a/models.py +++ b/models.py @@ -45,6 +45,7 @@ class Battery(Base): tested_date = Column(String(10), nullable=True) # YYYY-MM-DD of last test charge_cycles = Column(Integer, nullable=True) # number of charge cycles purchase_date = Column(String(10), nullable=True) # YYYY-MM-DD when purchased + storage_location = Column(String(100), nullable=True) # where stored when not installed device = relationship("Device", back_populates="batteries") diff --git a/templates/battery_detail.html b/templates/battery_detail.html index 634c82e..f6aaba7 100644 --- a/templates/battery_detail.html +++ b/templates/battery_detail.html @@ -66,6 +66,7 @@ {% endif %} {{ meta_row("Charge Cycles", battery.charge_cycles) }} {{ meta_row("Purchase Date", battery.purchase_date) }} + {{ meta_row("Storage", battery.storage_location) }} {% if battery.notes %} Notes @@ -142,6 +143,21 @@ +
+ + + +
+