diff --git a/expense_tracker/settings.py b/expense_tracker/settings.py index ce01798..478cfd4 100644 --- a/expense_tracker/settings.py +++ b/expense_tracker/settings.py @@ -20,38 +20,37 @@ # Application definition INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'expenses', - 'tailwind', - 'django_browser_reload', - 'allauth', - 'allauth.account', - 'allauth.socialaccount', + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "expenses", + "tailwind", + "django_browser_reload", + "allauth", + "allauth.account", + "allauth.socialaccount", ] AUTHENTICATION_BACKENDS = [ - 'django.contrib.auth.backends.ModelBackend', - 'allauth.account.auth_backends.AuthenticationBackend', + "django.contrib.auth.backends.ModelBackend", + "allauth.account.auth_backends.AuthenticationBackend", ] SITE_ID = 1 MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'django_browser_reload.middleware.BrowserReloadMiddleware', - 'allauth.account.middleware.AccountMiddleware', - + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", + "django_browser_reload.middleware.BrowserReloadMiddleware", + "allauth.account.middleware.AccountMiddleware", ] ROOT_URLCONF = "expense_tracker.urls" diff --git a/expense_tracker/urls.py b/expense_tracker/urls.py index 4973dae..a428a65 100644 --- a/expense_tracker/urls.py +++ b/expense_tracker/urls.py @@ -19,8 +19,8 @@ from django.urls import path, include urlpatterns = [ - path('admin/', admin.site.urls), - path('', include('expenses.urls')), - path('accounts/', include('allauth.urls')), + path("admin/", admin.site.urls), + path("", include("expenses.urls")), + path("accounts/", include("allauth.urls")), path("__reload__/", include("django_browser_reload.urls")), ] diff --git a/expenses/forms.py b/expenses/forms.py index 5bf8d96..1668052 100644 --- a/expenses/forms.py +++ b/expenses/forms.py @@ -1,13 +1,14 @@ from django import forms from .models import Expense + class ExpenseForm(forms.ModelForm): class Meta: model = Expense - fields = ['date', 'category', 'amount', 'currency'] + fields = ["date", "category", "amount", "currency"] widgets = { - 'currency': forms.TextInput(attrs={'placeholder': 'e.g., USD, EUR'}), + "currency": forms.TextInput(attrs={"placeholder": "e.g., USD, EUR"}), } initial = { - 'currency': 'EUR', + "currency": "EUR", } diff --git a/expenses/migrations/0001_initial.py b/expenses/migrations/0001_initial.py deleted file mode 100644 index 9a163a2..0000000 --- a/expenses/migrations/0001_initial.py +++ /dev/null @@ -1,32 +0,0 @@ -# Generated by Django 5.0.7 on 2024-07-12 11:35 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Month', - fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=50)), - ], - ), - migrations.CreateModel( - name='Expense', - fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('date', models.DateField()), - ('category', models.CharField(max_length=100)), - ('amount', models.DecimalField(decimal_places=2, max_digits=10)), - ('month', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='expenses', to='expenses.month')), - ], - ), - ] diff --git a/expenses/migrations/0002_expense_currency.py b/expenses/migrations/0002_expense_currency.py deleted file mode 100644 index 3cc0038..0000000 --- a/expenses/migrations/0002_expense_currency.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 5.0.7 on 2024-07-14 01:38 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('expenses', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='expense', - name='currency', - field=models.CharField(default='USD', max_length=3), - ), - ] diff --git a/expenses/migrations/0003_alter_expense_currency.py b/expenses/migrations/0003_alter_expense_currency.py deleted file mode 100644 index 08c2a82..0000000 --- a/expenses/migrations/0003_alter_expense_currency.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 5.0.7 on 2024-07-14 14:37 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('expenses', '0002_expense_currency'), - ] - - operations = [ - migrations.AlterField( - model_name='expense', - name='currency', - field=models.CharField(blank=True, default='USD', max_length=3, null=True), - ), - ] diff --git a/expenses/migrations/__init__.py b/expenses/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/expenses/models.py b/expenses/models.py index ec954f3..9d22807 100644 --- a/expenses/models.py +++ b/expenses/models.py @@ -6,7 +6,7 @@ class Month(models.Model): @property def total_expenses(self): - return self.expenses.aggregate(total=models.Sum('amount'))['total'] or 0 + return self.expenses.aggregate(total=models.Sum("amount"))["total"] or 0 def __str__(self): return self.name @@ -16,8 +16,8 @@ class Expense(models.Model): date = models.DateField() category = models.CharField(max_length=100) amount = models.DecimalField(max_digits=10, decimal_places=2) - month = models.ForeignKey(Month, related_name='expenses', on_delete=models.CASCADE) - currency = models.CharField(max_length=3, default='EUR', blank=True, null=True) + month = models.ForeignKey(Month, related_name="expenses", on_delete=models.CASCADE) + currency = models.CharField(max_length=3, default="EUR", blank=True, null=True) def __str__(self): return f"{self.category} - {self.amount} {self.currency or 'EUR'}" diff --git a/expenses/templates/expenses/add_expense.html b/expenses/templates/expenses/add_expense.html index 593cce5..f6a54b6 100644 --- a/expenses/templates/expenses/add_expense.html +++ b/expenses/templates/expenses/add_expense.html @@ -1,40 +1,71 @@ - -
- - + + +