Files
finance_app/init_db.py
anton 7d00cf062e Changes to be committed:
modified:   app.py
	modified:   init_db.py
	modified:   static/styles.css
	modified:   templates/index.html
	new file:   templates/login.html
	new file:   templates/register.html
2025-07-02 15:04:21 +03:00

31 lines
1.5 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, User, Transaction
from datetime import date, datetime
app.app_context().push()
# Создание таблиц
db.create_all()
# Добавление тестового пользователя
if not User.query.first():
test_user = User(username="testuser", email="test@example.com")
test_user.set_password("testpassword")
db.session.add(test_user)
db.session.commit()
# Добавление тестовых транзакций
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("База данных уже содержит данные")