From d2769743c8507af4f2290cd6e9a84bdb9d98574a Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 1 Aug 2019 16:17:21 +0200 Subject: [PATCH] Create medal db tables --- royalnet/database/tables/medalawards.py | 39 +++++++++++++++++++++++++ royalnet/database/tables/medals.py | 36 +++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 royalnet/database/tables/medalawards.py create mode 100644 royalnet/database/tables/medals.py 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""