You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
1009 B

from json import JSONEncoder
from sqlalchemy.sql import func
from app import db
class Location(db.Model):
__tablename__ = 'location'
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
longitude = db.Column(db.Numeric(precision=15, scale=10, asdecimal=False, decimal_return_scale=None), nullable=False) # maybe check asdecimal and decimal_return_scale later?
latitude = db.Column(db.Numeric(precision=15, scale=10, asdecimal=False, decimal_return_scale=None), nullable=False)
timestamp = db.Column(db.DateTime, server_default=func.now(), nullable=False)
def __str__(self):
return f'{self.longitude}, {self.latitude}'
class LocationEncoder(JSONEncoder):
def default(self, location):
return {
'username' : location.user.name,
'longitude' : location.longitude,
'latitude' : location.latitude,
'timestamp_utc' : str(location.timestamp)
}