class Post_Portfolio(db.Model): id = db.Column(db.Integer, primary_key=True) name_inv = db.Column(db.String(20), nullable=False) category_inv = db.Column(db.String(20), nullable=False) amount_inv = db.Column(db.String, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Post_Portfolio('{self.name_inv}', '{self.category_inv}','{self.amount_inv}')"
class Post(db.Model): """create the Planned Budget table""" __tablename__ = 'post' id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(30), nullable=False, default='planned') category = db.Column(db.String(30), nullable=False, default=None) name = db.Column(db.String(30), nullable=True) planned_amount_month = db.Column(db.Float, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) date_period = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) comments = db.Column(db.Text, nullable=True) def __repr__(self): return f"Post('{self.title}, '{self.category}'\
class ActualPost(db.Model): """create the Actuals table""" __tablename__ = 'actualpost' id = db.Column(db.Integer, primary_key=True, autoincrement=True) title_actual = db.Column(db.String(30), nullable=False, default='actual') category_actual = db.Column(db.String(30), nullable=False, default=None) actual_amount_name = db.Column(db.String(30), nullable=True) actual_amount = db.Column(db.Float, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) comments = db.Column(db.Text, nullable=True) def __repr__(self): return f"ActualPost('{self.title_actual}, '{self.category_actual}'\
class Budget(db.Model): """ Represents a budget app user's budget. """ __tablename__ = 'budgets' # Basic user info id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(50), nullable=False) description = db.Column(db.Text) # The total amount allocated for a budget amount = db.Column(db.Integer, default=0) # This can be expanded upon as it's own model # i.e. "Monthly Budget", "House Repairs", etc. category = db.Column(db.String(50)) # Relationships budget_items = db.relationship('BudgetItem', backref='Budget', cascade="all, delete-orphan") created_by = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) # timestamps created_at = db.Column(db.DateTime, server_default=func.now()) updated_at = db.Column(db.DateTime, onupdate=func.now()) def __init__(self, name, created_by, amount=0, description=None, category=None, created_at=None, updated_at=None): self.name = name self.description = description self.category = category self.amount = amount self.created_by = created_by self.created_at = created_at self.updated_at = updated_at def __str__(self): return '<%s>' % self # TODO: move into a parent model class as it's shared functionality def create(self): db.session.add(self) db.session.commit() return self def update(self): db.session.add(self) db.session.commit() db.session.refresh(self) return self def delete(self): db.session.delete(self) db.session.commit() return self
class BudgetItem(db.Model): """ Represents a budget item. """ __tablename__ = 'budget_items' # Basic info id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(50), nullable=False) description = db.Column(db.Text) # This represents a ledger amount (12.45) or 12.45 # Think in accounting terms # This value will be used to determine if the user is going over budget amount = db.Column(db.Integer) # This can be expanded upon as it's own model # i.e. "Monthly Budget", "House Repairs", etc. category = db.Column(db.String(50)) # Relationships budget_id = db.Column(db.Integer, db.ForeignKey('budgets.id'), nullable=False) # User that created the item, open for collaboration if # multiple users want to work on the same budget created_by = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) # timestamps created_at = db.Column(db.DateTime, server_default=func.now()) updated_at = db.Column(db.DateTime, onupdate=func.now()) def __init__(self, name, budget_id, created_by, amount=0, description=None, category=None, created_at=None, updated_at=None): self.name = name self.description = description self.category = category self.amount = amount self.budget_id = budget_id self.created_by = created_by self.created_at = created_at self.updated_at = updated_at def __str__(self): return '<%s>' % self # TODO: move into a parent model class as it's shared functionality def create(self): db.session.add(self) db.session.commit() return self def update(self): db.session.add(self) db.session.commit() db.session.refresh(self) return self def delete(self): db.session.delete(self) db.session.commit() return self