-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodels.py
193 lines (154 loc) · 6.49 KB
/
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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
from app import db
import datetime
from werkzeug.security import generate_password_hash, check_password_hash
class User(db.Model):
__tablename__ = 'User'
username = db.Column(db.String(120),primary_key=True)
password = db.Column(db.String(120))
name = db.Column(db.String(200))
email = db.Column(db.String(80),unique=True)
mobile = db.Column(db.String(14))
dob = db.Column(db.Date)
pan_no = db.Column(db.String(10),unique=True)
aadhar_no = db.Column(db.String(12),unique=True)
def __init__(self,username,raw_pass,name,email,mobile,dob,pan_no,aadhar_no):
self.username = username
self.set_password(raw_pass)
self.name = name
self.email = email
self.mobile = mobile
self.dob = dob
self.pan_no = pan_no
self.aadhar_no = aadhar_no
def __repr__(self):
return '<User %r>' % self.username
def set_password(self,raw_pass):
self.password = generate_password_hash(raw_pass)
def check_password(self,password):
return check_password_hash(self.password,password)
@classmethod
def login_user(cls,username,password):
user = cls.query.filter_by(username=username).first()
if user == None:
return None
if user.check_password(password):
return user
class Bank_Details(db.Model):
__tablename__ = 'Bank_Details'
account_no = db.Column(db.BigInteger,primary_key=True,autoincrement=False)
User_id = db.Column(db.String(120),db.ForeignKey('User.username',ondelete='CASCADE'))
user = db.relationship('User',backref=db.backref('User_bank',passive_deletes=True))
bank_name = db.Column(db.String(120))
bank_branch = db.Column(db.String(120))
bank_IFSC = db.Column(db.String(20))
def __init__(self,bank_ac_no,User_id,bank_name,bank_branch,bank_IFSC):
self.account_no = bank_ac_no
self.User_id = User_id
self.bank_name = bank_name
self.bank_branch = bank_branch
self.bank_IFSC = bank_IFSC
def __repr__(self):
return '<Bank_ac %r>' % self.account_no
@classmethod
def get_bank(cls,User_id):
bank = cls.query.filter_by(user=User_id).first()
return bank
class demat(db.Model):
__tablename__ = 'demat'
account_no = db.Column(db.BigInteger,primary_key=True)
User_id = db.Column(db.String(120),db.ForeignKey('User.username',ondelete='CASCADE'))
user = db.relationship('User',backref=db.backref('User_demat',passive_deletes=True))
Funds_Avail = db.Column(db.Numeric)
Funds_Blocked = db.Column(db.Numeric)
Funds_Invested = db.Column(db.Numeric)
def __init__(self,User_id):
self.User_id = User_id
self.Funds_Avail = 500000
self.Funds_Blocked = 0
self.Funds_Invested = 0
def __repr__(self):
return '<demat_ac %r>' % self.account_no
@classmethod
def get_ac(cls,User_id):
dmt = cls.query.filter_by(User_id=User_id).first()
return dmt
class company(db.Model):
__tablename__ = 'company'
id = db.Column(db.String(150),primary_key=True)
name = db.Column(db.String(200),unique=True)
sector = db.Column(db.String(100))
year_low = db.Column(db.Numeric)
year_high = db.Column(db.Numeric)
def __init__(self,id,name,sector,year_low,year_high):
self.id = id
self.name = name
self.sector = sector
self.year_low = year_low
self.year_high = year_high
def __repr__(self):
return '<comapny %r>' % self.id
class shares(db.Model):
__tablename__ = 'shares'
share_id = db.Column(db.Integer,primary_key=True)
company_id = db.Column(db.String(150),db.ForeignKey('company.id',ondelete='CASCADE'))
company = db.relationship('company',backref=db.backref('share_company',passive_deletes=True))
prev_close = db.Column(db.Numeric)
open_price = db.Column(db.Numeric)
volume = db.Column(db.Integer)
date = db.Column(db.DateTime,default=datetime.datetime.now)
day_low = db.Column(db.Numeric)
day_high = db.Column(db.Numeric)
def __init__(self,company_id,prev_close,open_price,volume,date,day_low,day_high):
self.company_id = company_id
self.prev_close = prev_close
self.open_price = open_price
self.volume = volume
self.date = date
self.day_low = day_low
self.day_high = day_high
def __repr__(self):
return '<shares %r>' % self.company_id
class portfolio(db.Model):
id = db.Column(db.Integer,primary_key=True)
company_id = db.Column(db.String(150),db.ForeignKey('company.id',ondelete='CASCADE'))
company = db.relationship('company',backref=db.backref('portfolio_company',passive_deletes=True))
quantity = db.Column(db.Integer)
bid_price = db.Column(db.Numeric)
demat_ac = db.Column(db.BigInteger,db.ForeignKey('demat.account_no',ondelete='CASCADE'))
demat = db.relationship('demat',backref=db.backref('portfolio_demat',passive_deletes=True))
def __init__(self,company_id,quantity,bid_price,demat_ac):
self.company_id = company_id
self.quantity = quantity
self.bid_price = bid_price
self.demat_ac = demat_ac
def __repr__(self):
return '<owned %r>' % self.id
@classmethod
def get_shares(cls,account_no):
shr = cls.query.filter_by(demat_ac=account_no).all()
return shr
class transactions(db.Model):
id = db.Column(db.Integer,primary_key=True)
timestamp = db.Column(db.DateTime,default=datetime.datetime.now)
company_id = db.Column(db.String(150),db.ForeignKey('company.id',ondelete='CASCADE'))
company = db.relationship('company',backref=db.backref('trans_company',passive_deletes=True))
demat_ac = db.Column(db.BigInteger,db.ForeignKey('demat.account_no',ondelete='CASCADE'))
demat = db.relationship('demat',backref=db.backref('trans_demat',passive_deletes=True))
buy = db.Column(db.Boolean)
price = db.Column(db.Numeric)
quantity = db.Column(db.Integer)
status = db.Column(db.Integer)
def __init__(self,company_id,company_name,demat_ac,buy,price,quantity,status = 0):
self.company_id = company_id
self.demat_ac = demat_ac
self.buy = buy
self.price = price
self.quantity = quantity
self.status = status
self.company_name=company_name
def __repr__(self):
return '<trans %r>' % self.id
@classmethod
def get_trs(cls,account_no):
dmt = cls.query.filter_by(demat_ac=account_no).order_by(transactions.timestamp.desc()).all()
return dmt