Добавил первые файлы приложения
This commit is contained in:
25
init_db.py
Normal file
25
init_db.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import os
|
||||
from app import db, app, Transaction
|
||||
from datetime import date
|
||||
|
||||
app.app_context().push()
|
||||
|
||||
# Создание таблиц
|
||||
db.create_all()
|
||||
|
||||
# Добавление начальных данных
|
||||
if not Transaction.query.first():
|
||||
transactions = [
|
||||
Transaction(type='income', amount=50000, category='Зарплата', date=date(2023, 10, 15), description='Основная зарплата'),
|
||||
Transaction(type='expense', amount=15000, category='Аренда', date=date(2023, 10, 5), description='Аренда квартиры'),
|
||||
Transaction(type='expense', amount=3500, category='Продукты', date=date(2023, 10, 12), description='Супермаркет'),
|
||||
Transaction(type='expense', amount=2500, category='Транспорт', date=date(2023, 10, 18), description='Бензин'),
|
||||
Transaction(type='income', amount=10000, category='Фриланс', date=date(2023, 10, 20), description='Веб-разработка')
|
||||
]
|
||||
|
||||
for t in transactions:
|
||||
db.session.add(t)
|
||||
db.session.commit()
|
||||
print("База данных инициализирована с тестовыми данными")
|
||||
else:
|
||||
print("База данных уже содержит данные")
|
||||
Reference in New Issue
Block a user