Getting one to many working... attempt 1.
This commit is contained in:
parent
ea8e8a9df7
commit
811b534b89
5 changed files with 48 additions and 74 deletions
|
|
@ -17,7 +17,7 @@ class WorkLog(Base, CRUDMixin):
|
|||
contact: Mapped[Optional['User']] = relationship('User', back_populates='work_logs')
|
||||
contact_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"), nullable=True, index=True)
|
||||
|
||||
updates: Mapped[List['WorkNote']] = relationship('WorkNote', back_populates='work_log', cascade='all, delete-orphan')
|
||||
updates: Mapped[List['WorkNote']] = relationship('WorkNote', back_populates='work_log', cascade='all, delete-orphan', order_by='WorkNote.timestamp.desc()')
|
||||
|
||||
work_item: Mapped[Optional['Inventory']] = relationship('Inventory', back_populates='work_logs')
|
||||
work_item_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey('inventory.id'), nullable=True, index=True)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,15 @@
|
|||
<div class="col mt-3">
|
||||
UPDATES NOT IMPLEMENTED YET
|
||||
</div>
|
||||
{% set items = (field.template_ctx.instance.updates or []) %}
|
||||
<ul class="list-group mt-3">
|
||||
{% for n in items %}
|
||||
<li class="list-group-item">
|
||||
<div class="d-flex justify-content-between align-items-start">
|
||||
<div class="me-3" style="white-space: pre-wrap;">{{ n.content }}</div>
|
||||
<small class="text-muted">
|
||||
{{ n.timestamp.strftime("%Y-%m-%d %H:%M") if n.timestamp else "" }}
|
||||
</small>
|
||||
</div>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="list-group-item text-muted">No updates yet.</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
Loading…
Add table
Add a link
Reference in a new issue