-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
24 lines (20 loc) · 740 Bytes
/
Copy pathmodels.py
File metadata and controls
24 lines (20 loc) · 740 Bytes
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 datetime import datetime, UTC
db = SQLAlchemy()
class Contact(db.Model):
__tablename__ = 'contacts'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), nullable=False)
phone = db.Column(db.String(20), nullable=False)
email = db.Column(db.String(120))
type = db.Column(db.String(20), nullable=False)
created_at = db.Column(db.DateTime, default=lambda: datetime.now(UTC))
def to_dict(self):
return {
'id': self.id,
'name': self.name,
'phone': self.phone,
'email': self.email,
'type': self.type,
'created_at': self.created_at.isoformat()
}