class Service(db.Model): id = db.Column(db.Integer, primary_key = True) service_name = db.Column(db.String(32), index = True, nullable = False) price_per = db.Column(db.Float, nullable = False) price_total = db.Column(db.Float, nullable = False) amount = db.Column(db.Integer, nullable = False) invoice_id = db.Column(db.Integer, db.ForeignKey('invoice.id'), nullable = False) invoice = db.relationship("Invoice", backref="invoice_for_service", foreign_keys = [invoice_id]) def __repr__(self): return '{}st {} {}kr'.format(self.amount, self.service_name, self.price_total)
class Invoice(db.Model): id = db.Column(db.Integer, primary_key = True) price = db.Column(db.Float) date = db.Column(db.DateTime, index = True, default = datetime.now) customer_id = db.Column(db.Integer, db.ForeignKey('customer.id'), nullable = False) sender_id = db.Column(db.Integer, db.ForeignKey('sender.id'), nullable = False) # this is a link to all services handled by the invoice payed_service = db.relationship("Service", primaryjoin=id==Service.invoice_id, cascade="all,delete") def __repr__(self): return 'ID:{}\nmottagare:{}\ndatum:{}\npris:{}\n{}'.format(self.id, self.customer_id, self.date, self.price, self.payed_service) # function to update total price on the invoice def setPrice(self): price = 0 for service in self.payed_service: price = price + service.price_total self.price = round(price,2) # function to get the date of the invoice def getDate(self): return self.date.date()
class Recipe(db.Model): id = db.Column(db.Integer, primary_key=True) owner_id = db.Column(db.Integer, db.ForeignKey('user.id')) name = db.Column(db.String(32)) ingredients = db.Column(db.String(140)) time = db.Column(db.Integer) body = db.Column(db.String(500)) timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) def __repr__(self): return '<Recipe {}>'.format(self.body)
class TodoList(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), nullable=False, default="My Todo List") items = db.relationship('TodoItem', backref='list', lazy='dynamic') ownerID = db.Column(db.Integer, db.ForeignKey('account.id'))
class TodoItem(db.Model): id = db.Column(db.Integer, primary_key=True) listID = db.Column(db.Integer, db.ForeignKey('todo_list.id')) description = db.Column(db.String(100), nullable=False, default="")