ogn-python/app/model/receiver.py

34 wiersze
1.0 KiB
Python
Czysty Zwykły widok Historia

2017-10-03 11:31:24 +00:00
from geoalchemy2.shape import to_shape
from geoalchemy2.types import Geometry
2015-11-15 10:59:52 +00:00
from .geo import Location
2015-11-15 10:59:52 +00:00
2019-08-31 08:14:41 +00:00
from app import db
2015-11-15 10:59:52 +00:00
2019-02-10 12:10:19 +00:00
class Receiver(db.Model):
__tablename__ = "receivers"
2015-11-15 10:59:52 +00:00
2019-02-10 12:25:24 +00:00
id = db.Column(db.Integer, primary_key=True)
2019-08-31 08:14:41 +00:00
location_wkt = db.Column("location", Geometry("POINT", srid=4326))
2019-02-10 12:25:24 +00:00
altitude = db.Column(db.Float(precision=2))
2019-02-10 12:25:24 +00:00
name = db.Column(db.String(9), index=True)
firstseen = db.Column(db.DateTime, index=True)
lastseen = db.Column(db.DateTime, index=True)
version = db.Column(db.String)
platform = db.Column(db.String)
# Relations
2019-08-31 08:14:41 +00:00
country_id = db.Column(db.Integer, db.ForeignKey("countries.gid", ondelete="SET NULL"), index=True)
country = db.relationship("Country", foreign_keys=[country_id], backref=db.backref("receivers", order_by="Receiver.name.asc()"))
@property
def location(self):
if self.location_wkt is None:
return None
coords = to_shape(self.location_wkt)
return Location(lat=coords.y, lon=coords.x)