Answer the question
In order to leave comments, you need to log in
What is the correct way to create a database model in Flask in combination with SQLAlchemy?
Good afternoon,
I have the following database model
class Sensor(db.Model):
__tablename__ = 'sensor'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64), index=True, unique=False)
unit = relationship('Unit')
class Value(db.Model):
__tablename__ = 'value'
id = db.Column(db.Integer, primary_key=True)
value = db.Column(db.Float, index=False, unique=False)
timestamp = db.Column(db.DateTime)
sensor_id = db.Column(db.Integer, db.ForeignKey('sensor.id'))
sensor = db.relationship('Sensor', backref='value', lazy = 'select')
class Unit(db.Model):
__tablename__ = 'unit'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(32), index=True, unique=False)
description = db.Column(db.String(32), index=True, unique=False)
db_result = Value.query.filter(Value.sensor_id == sensor_id).limit(100).all()
db_result.sensor.unit.description
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question