Adding AugmentedItem notes
This commit is contained in:
1 parent
30a13644ce
commit
34679d53e8
10 files changed
+254
-12
No files matched your search
@@ -8,7 +8,7 @@ from app.models.associations import (
|
||||
from app.models.attachment_point import AttachmentPoint
|
||||
from app.models.attachment_point_name import AttachmentPointName
|
||||
from app.models.audit_log import AuditLog
|
||||
from app.models.augmented_part import AugmentedPart
|
||||
from app.models.augmented_part import AugmentedPart, AugmentedPartNote
|
||||
from app.models.clamp_connection import ClampConnection
|
||||
from app.models.fit import Fit, FitLabel, FitNote
|
||||
from app.models.imported_part import ImportedPart
|
||||
@@ -32,6 +32,7 @@ __all__ = [
|
||||
"AttachmentPointName",
|
||||
"AuditLog",
|
||||
"AugmentedPart",
|
||||
"AugmentedPartNote",
|
||||
"ClampConnection",
|
||||
"Fit",
|
||||
"FitLabel",
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
from sqlalchemy import ForeignKey, String
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, ForeignKey, String, Text, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.core.database import Base
|
||||
@@ -45,3 +47,30 @@ class AugmentedPart(Base):
|
||||
scope_model: Mapped[ScopeModel | None] = relationship(lazy="selectin")
|
||||
part_type: Mapped[PartType] = relationship(lazy="selectin")
|
||||
sub_part_type: Mapped[SubPartType | None] = relationship(lazy="selectin")
|
||||
notes: Mapped[list["AugmentedPartNote"]] = relationship(
|
||||
back_populates="augmented_part",
|
||||
lazy="selectin",
|
||||
order_by="AugmentedPartNote.created_at",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
|
||||
|
||||
class AugmentedPartNote(Base):
|
||||
__tablename__ = "augmented_part_notes"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
augmented_part_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("augmented_parts.id", ondelete="CASCADE"), nullable=False
|
||||
)
|
||||
user_id: Mapped[int | None] = mapped_column(
|
||||
ForeignKey("users.id", ondelete="SET NULL"), nullable=True
|
||||
)
|
||||
# Denormalized snapshot of who wrote the note (mirrors FitNote.username), so
|
||||
# the note stays attributable even if the user is later deleted.
|
||||
username: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
body: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
|
||||
augmented_part: Mapped[AugmentedPart] = relationship(back_populates="notes")
|
||||
Reference in new issue
Block a user