-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
41 lines (35 loc) · 1.84 KB
/
models.py
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
31
32
33
34
35
36
37
38
39
40
41
#Création des classes associées à la base de données (ORM)
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Farm(db.Model):
__tablename__ = "farm"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String,unique=True, nullable=False)
class Parcel(db.Model):
__tablename__ = "parcel"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String,unique=True, nullable=False)
geometry = db.Column(db.String,unique=True, nullable=False)
objects=db.relationship('Object',backref='parcel',lazy=True)
farm_id = db.Column(db.Integer,db.ForeignKey("farm.id"),unique=True, nullable=False)
class Object(db.Model):
__tablename__ = "object"
id = db.Column(db.Integer, primary_key=True)
latitude = db.Column(db.Float ,unique=True, nullable=False)
longitude = db.Column(db.Float ,unique=True, nullable=False)
ff=db.relationship('Parcel',backref='object',lazy=True)
sensors=db.relationship('Sensor_object',backref='object',lazy=True)
parcel_id = db.Column(db.Integer, db.ForeignKey("parcel.id"),unique=True, nullable=False)
class Sensor_object(db.Model):
__tablename__ = "sensor_object"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String ,unique=True, nullable=False)
unit = db.Column(db.String ,unique=True, nullable=False)
values=db.relationship('Value',backref='sensor',lazy=True)
object_id= db.Column(db.Integer, db.ForeignKey("object.id"),unique=True, nullable=False)
class Value(db.Model):
__tablename__ = "value"
id = db.Column(db.Integer, primary_key=True)
created = db.Column(db.DateTime ,unique=True, nullable=False)
value = db.Column(db.Float ,unique=True, nullable=False)
sensor_object_id = db.Column(db.Integer, db.ForeignKey("sensor_object.id"),unique=True, nullable=False)