Добавил первые файлы приложения

This commit is contained in:
2025-06-29 16:27:10 +03:00
parent 1e9cc84c8a
commit e5b217c5b7
7 changed files with 711 additions and 0 deletions

25
init_db.py Normal file
View 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("База данных уже содержит данные")