Some work on event models

This commit is contained in:
Ferdinand Thiessen 2020-10-20 19:25:10 +02:00
parent 854a1f6156
commit 92626dc0c6
2 changed files with 24 additions and 35 deletions

View File

@ -20,7 +20,7 @@ def login_user(username, password):
def update_user(user):
current_app.config["FG_AUTH_BACKEND"].update_user(user)
if not user.display_name:
user.display_name = user.firstname[0] + user.lastname
user.display_name = "{} {}".format(user.firstname, user.lastname)
db.session.commit()

View File

@ -1,76 +1,65 @@
from . import ModelSerializeMixin
from ..database import db
class Event(db.Model):
class Event(db.Model, ModelSerializeMixin):
"""Model for an Event"""
__tablename__ = "event"
id = db.Column(db.Integer, primary_key=True)
begin = db.Column(db.DateTime, nullable=False)
end = db.Column(db.DateTime)
description = db.Column(db.String(240))
kind_id = db.Column(db.Integer, db.ForeignKey("event_kind.id", ondelete="CASCADE"), nullable=False)
kind = db.relationship("EventKind")
slots = db.relationship("EventSlot", back_populates="event", cascade="all, delete")
# notices = db.relationship("EventNotice", back_populates="event")
def serialize(self):
return {"id": self.id, "begin": self.begin, "end": self.end, "description": self.description, "kind": self.kind}
_kind_id = db.Column(db.Integer, db.ForeignKey("event_kind.id", ondelete="CASCADE"), nullable=False)
class EventKind(db.Model):
class EventKind(db.Model, ModelSerializeMixin):
"""Model for an EventKind"""
__tablename__ = "event_kind"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(30), nullable=False, unique=True)
def serialize(self):
return {"id": self.id, "name": self.name}
class EventSlot(db.Model):
class EventSlot(db.Model, ModelSerializeMixin):
"""Model for an EventSlot"""
__tablename__ = "event_slot"
id = db.Column(db.Integer, primary_key=True)
start = db.Column(db.DateTime)
end = db.Column(db.DateTime)
event_id = db.Column(db.Integer, db.ForeignKey("event.id"), nullable=False)
event = db.relationship("Event", back_populates="slots")
slots = db.relationship("JobSlot", back_populates="event_slot")
def serialize(self):
return {
"id": self.id,
"start": self.start,
"end": self.end,
"event": self.event_id,
}
_event_id = db.Column(db.Integer, db.ForeignKey("event.id"), nullable=False)
_event = db.relationship("Event", back_populates="slots")
class JobSlot(db.Model):
class JobSlot(db.Model, ModelSerializeMixin):
__tablename__ = "job_slot"
id = db.Column(db.Integer, primary_key=True)
needed_persons = db.Column(db.Numeric(precision=4, scale=2))
event_slot_id = db.Column(db.Integer, db.ForeignKey("event_slot.id"))
event_slot = db.relationship("EventSlot", back_populates="slots")
kind_id = db.Column(db.Integer, db.ForeignKey("job_kind.id"))
kind = db.relationship("JobKind")
jobs = db.relationship("Job", back_populates="slot")
_event_slot_id = db.Column(db.Integer, db.ForeignKey("event_slot.id"))
_event_slot = db.relationship("EventSlot", back_populates="slots")
_kind_id = db.Column(db.Integer, db.ForeignKey("job_kind.id"))
class Job(db.Model):
class Job(db.Model, ModelSerializeMixin):
__tablename__ = "job"
id = db.Column(db.Integer, primary_key=True)
value = db.Column(db.Numeric(precision=3, scale=2))
user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
user = db.relationship("User")
slot_id = db.Column(db.Integer, db.ForeignKey("job_slot.id"))
slot = db.relationship("JobSlot")
value = db.Column(db.Numeric(precision=3, scale=2))
_user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
_slot_id = db.Column(db.Integer, db.ForeignKey("job_slot.id"))
_slot = db.relationship("JobSlot")
_id = db.Column(db.Integer, primary_key=True)
class JobKind(db.Model):
class JobKind(db.Model, ModelSerializeMixin):
__tablename__ = "job_kind"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(30))
name = db.Column(db.String(30), nullable=False, unique=True)
_id = db.Column(db.Integer, primary_key=True)