flaschengeist/flaschengeist/system/models/event.py

79 lines
2.8 KiB
Python

from datetime import datetime
from typing import Optional
from . import ModelSerializeMixin
from .user import User
from ..database import db
class EventSlot(db.Model, ModelSerializeMixin):
"""Model for an EventSlot"""
__tablename__ = "event_slot"
id: int = db.Column(db.Integer, primary_key=True)
start: datetime = db.Column(db.DateTime)
end: Optional[datetime] = db.Column(db.DateTime)
slots: [any] = db.relationship("JobSlot", back_populates="_event_slot")
_event_id = db.Column("event_id", db.Integer, db.ForeignKey("event.id"), nullable=False)
_event = db.relationship("Event", back_populates="_slots")
class EventKind(db.Model, ModelSerializeMixin):
"""Model for an EventKind"""
__tablename__ = "event_kind"
name: str = db.Column(db.String(30), nullable=False, unique=True)
_id: int = db.Column("id", db.Integer, primary_key=True)
class Event(db.Model, ModelSerializeMixin):
"""Model for an Event"""
__tablename__ = "event"
id: int = db.Column(db.Integer, primary_key=True)
begin: datetime = db.Column(db.DateTime, nullable=False)
end: datetime = db.Column(db.DateTime)
description: str = db.Column(db.String(240))
kind: EventKind = db.relationship("EventKind")
# notices = db.relationship("EventNotice", back_populates="event")
_kind_id = db.Column("kind_id", db.Integer, db.ForeignKey("event_kind.id", ondelete="CASCADE"), nullable=False)
_slots: [EventSlot] = db.relationship("EventSlot", back_populates="_event", cascade="all, delete")
class Job(db.Model, ModelSerializeMixin):
__tablename__ = "job"
userid: str = None
value: float = db.Column(db.Numeric(precision=3, scale=2))
_id = db.Column("id", db.Integer, primary_key=True)
_user_id = db.Column("user_id", db.Integer, db.ForeignKey("user.id"))
_user: User = db.relationship("User")
_slot_id = db.Column("slot_id", db.Integer, db.ForeignKey("job_slot.id"))
_slot = db.relationship("JobSlot")
@property
def userid(self):
return self._user.userid
class JobKind(db.Model, ModelSerializeMixin):
__tablename__ = "job_kind"
name: str = db.Column(db.String(30), nullable=False, unique=True)
_id = db.Column("id", db.Integer, primary_key=True)
class JobSlot(db.Model, ModelSerializeMixin):
__tablename__ = "job_slot"
id: int = db.Column(db.Integer, primary_key=True)
needed_persons: float = db.Column(db.Numeric(precision=4, scale=2))
kind: JobKind = db.relationship("JobKind")
jobs: [Job] = db.relationship("Job", back_populates="_slot")
_event_slot_id = db.Column("event_slot_id", db.Integer, db.ForeignKey("event_slot.id"))
_event_slot = db.relationship("EventSlot", back_populates="slots")
_kind_id = db.Column("kind_id", db.Integer, db.ForeignKey("job_kind.id"))