Initial project import: Flask app, templates, init script, README
This commit is contained in:
24
init_db.py
Normal file
24
init_db.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from app import app, db, Frage
|
||||
|
||||
|
||||
def init_db():
|
||||
# Ensure we run DB commands inside the Flask application context
|
||||
with app.app_context():
|
||||
db.drop_all()
|
||||
db.create_all()
|
||||
|
||||
sample = [
|
||||
'Haben Sie besondere Ernährungsbedürfnisse?',
|
||||
'Benötigen Sie eine Übernachtung?',
|
||||
'Möchten Sie unseren Newsletter erhalten?'
|
||||
]
|
||||
for text in sample:
|
||||
f = Frage(text=text)
|
||||
db.session.add(f)
|
||||
db.session.commit()
|
||||
|
||||
print('DB initialisiert und Beispiel-Fragen angelegt.')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_db()
|
||||
Reference in New Issue
Block a user