-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
30 lines (24 loc) · 1.1 KB
/
models.py
File metadata and controls
30 lines (24 loc) · 1.1 KB
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
# models.py
from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin
from datetime import datetime
db = SQLAlchemy()
# User Model
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
password = db.Column(db.String(60), nullable=False)
images = db.relationship('Image', backref='owner', lazy=True)
def __repr__(self):
return f"User('{self.username}', '{self.email}')"
# Image Model
class Image(db.Model):
id = db.Column(db.Integer, primary_key=True)
filename = db.Column(db.String(100000), nullable=False)
path = db.Column(db.String(100000), nullable=False) # Relative path
upload_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
features = db.Column(db.PickleType, nullable=True) # To store feature vectors
def __repr__(self):
return f"Image('{self.filename}', '{self.upload_date}')"