mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Add event to the db
This commit is contained in:
parent
2d7149ae2d
commit
3d4c084d10
1 changed files with 22 additions and 0 deletions
22
db.py
22
db.py
|
@ -1,6 +1,7 @@
|
||||||
import datetime
|
import datetime
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import sessionmaker, relationship
|
from sqlalchemy.orm import sessionmaker, relationship
|
||||||
|
from sqlalchemy.ext.hybrid import hybrid_property
|
||||||
from sqlalchemy import Column, BigInteger, Integer, String, DateTime, ForeignKey, Float, Enum, create_engine, UniqueConstraint, PrimaryKeyConstraint, Boolean, or_, LargeBinary, Text, Date
|
from sqlalchemy import Column, BigInteger, Integer, String, DateTime, ForeignKey, Float, Enum, create_engine, UniqueConstraint, PrimaryKeyConstraint, Boolean, or_, LargeBinary, Text, Date
|
||||||
import requests
|
import requests
|
||||||
from errors import RequestError, NotFoundError, AlreadyExistingError
|
from errors import RequestError, NotFoundError, AlreadyExistingError
|
||||||
|
@ -846,6 +847,27 @@ class WikiLog(Base):
|
||||||
reason = Column(Text)
|
reason = Column(Text)
|
||||||
|
|
||||||
|
|
||||||
|
class Event(Base):
|
||||||
|
__tablename__ = "events"
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True)
|
||||||
|
author_id = Column(Integer, ForeignKey("royals.id"), nullable=False)
|
||||||
|
author = relationship("Royal")
|
||||||
|
name = Column(String, nullable=False)
|
||||||
|
description = Column(Text)
|
||||||
|
time = Column(DateTime, nullable=False)
|
||||||
|
|
||||||
|
@hybrid_property
|
||||||
|
def time_left(self) -> datetime.timedelta:
|
||||||
|
return self.time - datetime.datetime.now()
|
||||||
|
|
||||||
|
@time_left.setter
|
||||||
|
def time_left(self, value):
|
||||||
|
if not isinstance(value, datetime.timedelta):
|
||||||
|
raise TypeError("time_left should be a datetime.timedelta")
|
||||||
|
self.time = datetime.datetime.now() + value
|
||||||
|
|
||||||
|
|
||||||
# If run as script, create all the tables in the db
|
# If run as script, create all the tables in the db
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("Creating new tables...")
|
print("Creating new tables...")
|
||||||
|
|
Loading…
Reference in a new issue