kopia lustrzana https://github.com/glidernet/ogn-python
33 wiersze
1.0 KiB
Python
33 wiersze
1.0 KiB
Python
from geoalchemy2.shape import to_shape
|
|
from geoalchemy2.types import Geometry
|
|
|
|
from .geo import Location
|
|
|
|
from app import db
|
|
|
|
|
|
class Receiver(db.Model):
|
|
__tablename__ = "receivers"
|
|
|
|
name = db.Column(db.String(9), primary_key=True)
|
|
location_wkt = db.Column("location", Geometry("POINT", srid=4326))
|
|
altitude = db.Column(db.Float(precision=2))
|
|
|
|
firstseen = db.Column(db.DateTime, index=True)
|
|
lastseen = db.Column(db.DateTime, index=True)
|
|
timestamp = db.Column(db.DateTime, index=True)
|
|
version = db.Column(db.String)
|
|
platform = db.Column(db.String)
|
|
|
|
# Relations
|
|
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)
|