-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
24 lines (18 loc) · 895 Bytes
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from flask_sqlalchemy import SQLAlchemy
from werkzeug.security import generate_password_hash, check_password_hash
db = SQLAlchemy()
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
password_hash = db.Column(db.String(120), nullable=False)
def set_password(self, password):
self.password_hash = generate_password_hash(password)
def check_password(self, password):
return check_password_hash(self.password_hash, password)
class Deal(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), nullable=False)
status = db.Column(db.String(20), nullable=False)
commission = db.Column(db.Float, nullable=False)
def calculate_commission(self, deal_value, commission_rate):
self.commission = deal_value * commission_rate