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)) def __repr__(self): return '<User {}>'.format(self.username)
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 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 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 Customer(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(32), index = True, nullable = False) address = db.Column(db.String(64), index =True, nullable = True) city = db.Column(db.String(32), index = True, nullable = True) country = db.Column(db.String(32), index = True, nullable = True) email = db.Column(db.String(64), index = True, nullable = False) def __repr__(self): return 'ID:{} \n {} \n {}'.format(self.id, self.name, self.email)
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 Store(db.Model): id = db.Column(db.Integer, primary_key=True)
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="")
class Sender(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(32), index = True, nullable = False) address = db.Column(db.String(64), index =True, nullable = False) city = db.Column(db.String(32), index = True, nullable = False) country = db.Column(db.String(32), index = True, nullable = False) email = db.Column(db.String(64), index = True, nullable = False) zip_code = db.Column(db.Integer, nullable = False) organisation_number = db.Column(db.String(16), index = True, nullable = False) phone_number = db.Column(db.String(16), index = True, nullable = False) account_number = db.Column(db.String(16), index = True, nullable = False) payment_method = db.Column(db.String(16), index = True, nullable = False) complaint_link = db.Column(db.String(86), index = True, nullable = False, default = "https://i.imgur.com/JfHjOEP.jpg") logo_link = db.Column(db.String(86), index = True, nullable = False) is_main = db.Column(db.Boolean, default = False) # following two function are to change which "sender" invoices are sent from def set_main(self): self.is_main = True def remove_main(self): self.is_main = False def __repr__(self): return 'ID:{}\n {} \n {} \n {}: {} \n Main:{}'.format(self.id, self.name, self.email, self.payment_method, self.account_number, self.is_main)
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")