Files
finance_app/init_db.py

25 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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("База данных уже содержит данные")