Esempio n. 1
0
class Ticket(db.Model):
    __tablename__ = 'tickets'

    id = db.Column(db.String(40), primary_key=True, default=generate_uuid)
    created_at = db.Column(db.DateTime, nullable=False)
    time = db.Column(db.DateTime, nullable=False)

    availability_id = db.Column(db.String,
                                db.ForeignKey('availabilities.id'),
                                nullable=True)

    user_id = db.Column(db.String, db.ForeignKey('users.id'), nullable=True)
    user = db.relationship("User", back_populates="ticket")

    def __init__(self, time):
        self.time = time
        self.created_at = datetime.now()

    @classmethod
    def find_by_date(cls, date):
        return cls.query.filter_by(time=date)

    def save_or_update(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Esempio n. 2
0
class Comment(db.Model):
    __tablename__ = 'comments'

    id = db.Column(db.String(40), primary_key=True, default=generate_uuid)
    created_at = db.Column(db.DateTime, nullable=False)
    text = db.Column(db.String(250), nullable=False)

    # relationship
    comment_id = db.Column(db.String(40),
                           db.ForeignKey('comments.id'),
                           nullable=True)
    meal_id = db.Column(db.String(40),
                        db.ForeignKey('meals.id'),
                        nullable=True)
    user_id = db.Column(db.String(40),
                        db.ForeignKey('users.id'),
                        nullable=False)

    def __init__(self, text):
        self.text = text
        self.created_at = datetime.utcnow()

    @classmethod
    def get_by_id(cls, id):
        return cls.query.get(id)

    def save_or_update(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Esempio n. 3
0
class TicketHistory(db.Model):
    __tablename__ = 'ticket_histories'

    id = db.Column(db.String(40), primary_key=True, default=generate_uuid)
    created_at = db.Column(db.DateTime, nullable=False)

    user_id = db.Column(db.String, db.ForeignKey('users.id'), nullable=False)

    def __init__(self):
        self.created_at = datetime.now()

    def save_or_update(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
class Availability(db.Model):
    __tablename__ = 'availabilities'

    id = db.Column(db.String(40), primary_key=True, default=generate_uuid)
    created_at = db.Column(db.DateTime, nullable=False)
    time = db.Column(db.DateTime, nullable=False)

    meal_id = db.Column(db.String, db.ForeignKey('meals.id'), nullable=False)

    tickets = db.relationship('Ticket', backref='tickets', lazy=True)

    def __init__(self):
        self.created_at = datetime.now()

    def save_or_update(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Esempio n. 5
0
class TicketHistory(db.Model):
    __tablename__ = 'ticket_histories'

    id = db.Column(db.String(40), primary_key=True, default=generate_uuid)
    created_at = db.Column(db.DateTime, nullable=False)

    user_id = db.Column(db.String, db.ForeignKey('users.id'), nullable=False)

    def __init__(self):
        self.created_at = datetime.utcnow()

    def save_or_update(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()

    @classmethod
    def get_by_user_id(cls, user_id):
        return cls.query.filter_by(user_id=user_id).all()