FitTrackee/mpwo_api/server.py

36 lines
872 B
Python
Raw Normal View History

2018-04-09 22:09:58 +02:00
from mpwo_api import create_app, db
from mpwo_api.activities.models import Sport
2017-12-16 21:00:46 +01:00
from mpwo_api.users.models import User
2018-04-09 22:09:58 +02:00
app = create_app()
2017-12-16 21:00:46 +01:00
@app.cli.command()
2018-01-20 19:12:34 +01:00
def drop_db():
2017-12-16 21:00:46 +01:00
db.drop_all()
2018-01-20 19:12:34 +01:00
db.session.commit()
print('Database dropped.')
@app.cli.command()
def init_data():
"""Init the database."""
2018-01-01 16:59:46 +01:00
admin = User(
username='admin',
email='admin@example.com',
password='mpwoadmin')
2017-12-17 09:16:08 +01:00
admin.admin = True
db.session.add(admin)
db.session.add(Sport(label='Cycling (Sport)'))
db.session.add(Sport(label='Cycling (Transport)'))
db.session.add(Sport(label='Hiking'))
db.session.add(Sport(label='Mountain Biking'))
db.session.add(Sport(label='Running'))
db.session.add(Sport(label='Walking'))
2017-12-16 21:00:46 +01:00
db.session.commit()
print('Initial data stored in database.')
2017-12-16 21:00:46 +01:00
if __name__ == '__main__':
app.run()