-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
75 lines (61 loc) · 2.26 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
# -*- coding: UTF-8 -*-
# coding:utf-8
from app import db
from datetime import datetime
from flask_sqlalchemy import SQLAlchemy
from passlib.apps import custom_app_context as pwd_context
class User(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
email = db.Column(db.String(50), nullable=False)
sifre = db.Column(db.String(40), nullable=False)
tarih = db.Column(db.DateTime())
is_active = db.Column(db.Boolean())
alarm = db.relationship('Alarm', backref='user', lazy='dynamic')
def __init__(self, email, tarih, sifre, is_active):
self.email = email
self.tarih = tarih
if tarih is None:
self.tarih = datetime.now()
if is_active is None:
self.is_active = True
self.tarih = tarih
self.sifre = sifre
def hash_password(self, password):
self.sifre = pwd_context.encrypt(password)
def verify_password(self, password):
return pwd_context.verify(password, self.sifre)
def is_authenticated(self):
return True
def is_active(self):
return True
def is_anonymous(self):
return False
def get_id(self):
return unicode(str(self.id))
def __repr__(self):
return '<User %r>' % self.email
class Alarm(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
dovizAdi = db.Column(db.String(30))
mevcutDeger = db.Column(db.String(30))
beklenenDeger = db.Column(db.String(30))
oranTuru = db.Column(db.String(10))
tarih = db.Column(db.DateTime())
deviceID = db.Column(db.String())
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
isIOS = db.Column(db.Boolean)
isAndroid = db.Column(db.Boolean)
def __init__(self, dovizAdi, tarih, user_id, mevcutDeger, beklenenDeger, oranTuru, deviceID, isIOS, isAndroid):
self.dovizAdi = dovizAdi
self.mevcutDeger = mevcutDeger
self.beklenenDeger = beklenenDeger
self.oranTuru = oranTuru
self.deviceID = deviceID
self.user_id = user_id
self.isIOS = isIOS
self.isAndroid = isAndroid
if tarih is None:
tarih = datetime.now()
self.tarih = tarih
def __repr__(self):
return '<Alarm %r>' % self.dovizAdi