1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Create medal db tables

This commit is contained in:
Steffo 2019-08-01 16:17:21 +02:00
parent 021b4c53f9
commit d2769743c8
2 changed files with 75 additions and 0 deletions

View file

@ -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"<MedalAward of {self.medal} to {self.royal} on {self.date}>"

View file

@ -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"<Medal {self.mid}: {self.name}>"