diff --git a/royalnet/database/tables/medalawards.py b/royalnet/database/tables/medalawards.py new file mode 100644 index 00000000..fa16b538 --- /dev/null +++ b/royalnet/database/tables/medalawards.py @@ -0,0 +1,39 @@ +from sqlalchemy import Column, \ + Integer, \ + DateTime, \ + ForeignKey +from sqlalchemy.ext.declarative import declared_attr +from sqlalchemy.orm import relationship +from .royals import Royal +from .medals import Medal + + +class MedalAward: + __tablename__ = "MedalAward" + + @declared_attr + def award_id(self): + return Column(Integer, primary_key=True) + + @declared_attr + def date(self): + return Column(DateTime) + + @declared_attr + def medal_id(self): + return Column(Integer, ForeignKey("medals.mid"), nullable=False) + + @declared_attr + def royal_id(self): + return Column(Integer, ForeignKey("royal.uid"), nullable=False) + + @declared_attr + def medal(self): + return relationship("Medal", backref="awarded_to") + + @declared_attr + def royal(self): + return relationship("Royal", backref="medals_received") + + def __repr__(self): + return f"" diff --git a/royalnet/database/tables/medals.py b/royalnet/database/tables/medals.py new file mode 100644 index 00000000..5dc596a0 --- /dev/null +++ b/royalnet/database/tables/medals.py @@ -0,0 +1,36 @@ +from sqlalchemy import Column, \ + Integer, \ + String +from sqlalchemy.ext.declarative import declared_attr +# noinspection PyUnresolvedReferences +from .keygroups import Keygroup + + +class Medal: + __tablename__ = "medals" + + @declared_attr + def mid(self): + return Column(Integer, primary_key=True) + + @declared_attr + def name(self): + return Column(String, nullable=False) + + @declared_attr + def description(self): + return Column(String) + + @declared_attr + def icon(self): + return Column(String) + + @declared_attr + def classes(self): + return Column(String) + + def __str__(self): + return self.name + + def __repr__(self): + return f""