Skip to content
Snippets Groups Projects
Commit 605aa29d authored by erichard's avatar erichard
Browse files

move models.py from root to test

models.py is used for test purposes.
parent b63195e5
No related branches found
No related tags found
1 merge request!61Packager labelstower
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
db = SQLAlchemy(app)
element_label = db.Table('Element_Label', db.Model.metadata,
db.Column('id_element', db.Integer, db.ForeignKey('element.id')),
db.Column('id_label', db.Integer, db.ForeignKey('label.id'))
)
class Element(db.Model):
id = db.Column(db.INTEGER, primary_key=True)
element_name = db.Column(db.String(50), unique=True, nullable=False)
labels = db.relationship(
"Label",
secondary=element_label,
back_populates="elements")
class Label(db.Model):
id = db.Column(db.INTEGER, primary_key=True)
label_name = db.Column(db.String(50), unique=True, nullable=False)
father_id = db.Column(db.INTEGER, db.ForeignKey('label.id'))
children = db.relationship("Label",
backref=db.backref('parent', remote_side=[id])
)
aliases = db.relationship('Alias', back_populates='label')
elements = db.relationship(
"Element",
secondary=element_label,
back_populates="labels")
class Alias(db.Model):
alias_name = db.Column(db.String(100), primary_key=True)
id_label = db.Column(db.INTEGER, db.ForeignKey('label.id'), nullable=False)
label = db.relationship('Label', back_populates='aliases')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment