1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +00:00
royalnet/royalpack/tables/mmevents.py

57 lines
1.4 KiB
Python
Raw Normal View History

2020-04-08 20:00:57 +00:00
import pickle
from sqlalchemy import *
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr
class MMEvent:
__tablename__ = "mmevents"
@declared_attr
def creator_id(self):
return Column(Integer, ForeignKey("users.uid"), nullable=False)
@declared_attr
def creator(self):
return relationship("User", backref="mmevents_created")
@declared_attr
def mmid(self):
return Column(Integer, primary_key=True)
@declared_attr
def datetime(self):
2020-07-02 19:40:33 +00:00
return Column(DateTime)
2020-04-08 20:00:57 +00:00
@declared_attr
def title(self):
return Column(String, nullable=False)
@declared_attr
def description(self):
return Column(Text, nullable=False, default="")
@declared_attr
def interface(self):
return Column(String, nullable=False)
@declared_attr
def raw_interface_data(self):
# The default is a pickled None
return Column(Binary, nullable=False, default=b'\x80\x03N.')
@property
def interface_data(self):
return pickle.loads(self.raw_interface_data)
@interface_data.setter
def interface_data(self, value):
self.raw_interface_data = pickle.dumps(value)
2020-04-30 19:50:09 +00:00
@declared_attr
def interrupted(self):
return Column(Boolean, nullable=False, default=False)
2020-04-08 20:00:57 +00:00
def __repr__(self):
return f"<MMEvent {self.mmid}: {self.title}>"