Add term column

This commit is contained in:
Ian Keane 2026-06-11 17:28:07 -04:00
parent b5e2e8ab2a
commit 377462ed20
5 changed files with 100 additions and 1 deletions

View file

@ -61,6 +61,18 @@ class Tuning(db.Model):
return {"id": self.id, "name": self.name}
class Term(db.Model):
__tablename__ = "terms"
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String, nullable=False, unique=True)
entries = db.relationship("TuneByInstrument", back_populates="term")
def to_dict(self):
return {"id": self.id, "name": self.name}
class Tune(db.Model):
__tablename__ = "tunes"
@ -114,6 +126,7 @@ class TuneByInstrument(db.Model):
instrument_id = Column(Integer, ForeignKey("instruments.id", ondelete="CASCADE"), nullable=False)
learned_from_id = Column(Integer, ForeignKey("musicians.id", ondelete="SET NULL"), nullable=True)
tuning_id = Column(Integer, ForeignKey("tunings.id", ondelete="SET NULL"), nullable=True)
term_id = Column(Integer, ForeignKey("terms.id", ondelete="SET NULL"), nullable=True)
date_learned = Column(Date, nullable=True)
status = Column(String, nullable=True)
difficulty = Column(String, nullable=True)
@ -121,6 +134,7 @@ class TuneByInstrument(db.Model):
tune = db.relationship("Tune", back_populates="instruments")
instrument = db.relationship("Instrument", back_populates="entries")
tuning = db.relationship("Tuning", back_populates="entries")
term = db.relationship("Term", back_populates="entries")
learned_from_musician = db.relationship("Musician", back_populates="instrument_entries")
notes = db.relationship("TuneByInstrumentNote", back_populates="entry", cascade="all, delete-orphan")
@ -135,6 +149,8 @@ class TuneByInstrument(db.Model):
"date_learned": self.date_learned.isoformat() if self.date_learned else None,
"tuning_id": self.tuning_id,
"tuning": self.tuning.name if self.tuning else None,
"term_id": self.term_id,
"term": self.term.name if self.term else None,
"status": self.status,
"difficulty": self.difficulty,
"notes": [n.to_dict() for n in self.notes],
@ -151,6 +167,8 @@ class TuneByInstrument(db.Model):
"date_learned": self.date_learned.isoformat() if self.date_learned else None,
"tuning_id": self.tuning_id,
"tuning": self.tuning.name if self.tuning else None,
"term_id": self.term_id,
"term": self.term.name if self.term else None,
"status": self.status,
"difficulty": self.difficulty,
}