class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) password_hash = db.Column(db.String(128)) recipes = db.relationship('Recipe', backref='author', lazy='dynamic') def __repr__(self): return '<User {}>'.format(self.username)
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 Account(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(100), nullable=False) email = db.Column(db.String(120), nullable=False) password_hash = db.Column(db.String(128), nullable=True) lists = db.relationship('TodoList', backref='Owner', lazy='dynamic') def set_password(self, password): self.password_hash = generate_password_hash(password) def check_password(self, password): if (self.password_hash != None): return check_password_hash(self.password_hash, password) else: return False
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 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 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")