41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
from flask_sqlalchemy import SQLAlchemy
|
|
|
|
db = SQLAlchemy()
|
|
|
|
class Annotations(db.Model):
|
|
__tablename__ = 'annotations'
|
|
|
|
_id = db.Column("id", db.Integer, primary_key=True)
|
|
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
|
|
sample_id = db.Column(db.Integer, db.ForeignKey('samples.id'), nullable=False)
|
|
label = db.Column(db.String(32), nullable=False)
|
|
|
|
def __init__(self, user_id, sample_id, label):
|
|
self.user_id = user_id
|
|
self.sample_id = sample_id
|
|
self.label = label
|
|
|
|
class Users(db.Model):
|
|
__tablename__ = 'users'
|
|
|
|
_id = db.Column("id", db.Integer, primary_key=True)
|
|
name = db.Column(db.String(32), nullable=False)
|
|
surname = db.Column(db.String(32), nullable=False)
|
|
email = db.Column(db.String(64), unique=True, nullable=False)
|
|
annotations = db.relationship('Annotations', uselist=False, backref='user', lazy=True)
|
|
|
|
def __init__(self, name, surname, email):
|
|
self.name = name
|
|
self.surname = surname
|
|
self.email = email
|
|
|
|
class Samples(db.Model):
|
|
__tablename__ = 'samples'
|
|
|
|
_id = db.Column("id", db.Integer, primary_key=True)
|
|
text = db.Column(db.String(512), nullable=False)
|
|
annotations = db.relationship('Annotations', lazy=True, backref='sample') # corrected relationship and added backref
|
|
|
|
def __init__(self, text):
|
|
self.text = text
|