class Timestamps(object): """ Adds 2 columns: created_at and updated_at, these get updated automatically whenever the object is created or updated """ created_at = db.Column(db.DateTime, default=datetime.utcnow) updated_at = db.Column(db.DateTime)
class BudgetItem(db.Model, Model): __tablename__ = "budget_items" label = db.Column(db.String(200)) ves = db.Column(db.Integer) budget_id = db.Column(db.Integer, db.ForeignKey("budgets.id")) budget = db.relationship("Budget", back_populates="items")
class Rate(db.Model, Timestamps): __tablename__ = 'rates' id = db.Column(db.Integer, primary_key=True) price_per_coin = db.Column(db.Integer, primary_key=True) def is_expired(self): """ Returns True if the current rate is expired (older than a defined amount of time) """ delta = datetime.datetime.now() - self.created_at return delta.total_seconds() > 15*60
class Budget(db.Model, Model): __tablename__ = "budgets" title = db.Column(db.String(200)) items = db.relationship("BudgetItem", back_populates="budget")
class Model: id = db.Column(db.Integer, primary_key=True)