-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathmodels.py
24 lines (20 loc) · 851 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 import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///book.sqlite'
#app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root@localhost/book'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
class Contacts(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), nullable=False)
surname = db.Column(db.String(100), nullable=True)
email = db.Column(db.String(200), nullable=True, unique=True)
phone = db.Column(db.String(20), nullable=True, unique=False)
def __init__(self, name, surname, email, phone):
self.name = name
self.surname = surname
self.email = email
self.phone = phone
def __repr__(self):
return '<Contacts %r>' % self.name