Getting one to many working... attempt 1.

This commit is contained in:
Yaro Kasear 2025-09-25 15:24:50 -05:00
parent ea8e8a9df7
commit 811b534b89
5 changed files with 48 additions and 74 deletions

View file

@ -125,6 +125,24 @@ def init_entry_routes(app):
# Use the scoped_session proxy so teardown .remove() cleans it up
ScopedSession = current_app.extensions["crudkit"]["Session"]
if model == "worklog":
updates_cls = type(obj).updates.property.mapper.class_
updates_q = (ScopedSession.query(updates_cls)
.filter(updates_cls.work_log_id == obj.id,
updates_cls.is_deleted == False)
.order_by(updates_cls.timestamp.asc()))
all_updates = updates_q.all()
print(all_updates)
for f in fields_spec:
if f.get("name") == "updates" and f.get("type") == "template":
ctx = dict(f.get("template_ctx") or {})
ctx["updates"] = all_updates
f["template_ctx"] = ctx
break
print(fields_spec)
form = render_form(
cls,
obj.as_dict(),
@ -134,6 +152,11 @@ def init_entry_routes(app):
layout=layout,
submit_attrs={"class": "btn btn-primary mt-3"},
)
# sanity log
u = getattr(obj, "updates", None)
print("WORKLOG UPDATES loaded? ",
"None" if u is None else f"len={len(list(u))} ids={[n.id for n in list(u)]}")
return render_template("entry.html", form=form)
app.register_blueprint(bp_entry)