Updated SQL command
This commit is contained in:
parent
8839eedd40
commit
5a20130c37
|
@ -3,7 +3,7 @@ from flask_sqlalchemy import SQLAlchemy
|
||||||
import os
|
import os
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///./data.sqlite'
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.getenv('DB_LOC')
|
||||||
app.secret_key = os.environ.get('FGS_SECRET_KEY') or 'default secret key'
|
app.secret_key = os.environ.get('FGS_SECRET_KEY') or 'default secret key'
|
||||||
|
|
||||||
db = SQLAlchemy(app)
|
db = SQLAlchemy(app)
|
||||||
|
|
24
fgs/views.py
24
fgs/views.py
|
@ -1,4 +1,4 @@
|
||||||
from . import app
|
from . import app, db
|
||||||
from .jwt import jwt_required
|
from .jwt import jwt_required
|
||||||
from .model import *
|
from .model import *
|
||||||
from flask import g, jsonify, request, abort
|
from flask import g, jsonify, request, abort
|
||||||
|
@ -25,18 +25,16 @@ def me():
|
||||||
@app.route('/collars')
|
@app.route('/collars')
|
||||||
@jwt_required
|
@jwt_required
|
||||||
def collars():
|
def collars():
|
||||||
active_collars = Collar.query.\
|
active_collars = []
|
||||||
filter_by(active=True).\
|
for collar in Collar.query.filter_by(active=True).all():
|
||||||
join(DataPoint, isouter=True).\
|
max_point = DataPoint.query.filter_by(collar_id=collar.id).\
|
||||||
order_by(DataPoint.datetime.desc()).\
|
order_by(DataPoint.datetime.desc()).\
|
||||||
group_by(Collar.id).\
|
first()
|
||||||
with_entities(
|
active_collars.append(
|
||||||
Collar.id, Collar.name,
|
{'id': collar.id, 'name': collar.name, 'pos':
|
||||||
DataPoint.longitude, DataPoint.latitude).\
|
{'longitude': max_point.longitude, 'latitude': max_point.latitude}}
|
||||||
all()
|
)
|
||||||
active_collars = [
|
|
||||||
{'id': id, 'name': name, 'pos': {'longitude': lo, 'latitude': la}}
|
|
||||||
for (id, name, lo, la) in active_collars]
|
|
||||||
return jsonify(active_collars)
|
return jsonify(active_collars)
|
||||||
|
|
||||||
@app.route('/collars/<int:id>/history')
|
@app.route('/collars/<int:id>/history')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user