Skip to content

Commit

Permalink
Updated the ui, formatted the files and removed unnecessary migration…
Browse files Browse the repository at this point in the history
…s folder
  • Loading branch information
houmanhafez committed Jul 14, 2024
1 parent 8060a8a commit 10ed465
Show file tree
Hide file tree
Showing 14 changed files with 378 additions and 323 deletions.
47 changes: 23 additions & 24 deletions expense_tracker/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions expense_tracker/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
]
7 changes: 4 additions & 3 deletions expenses/forms.py
Original file line number Diff line number Diff line change
@@ -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",
}
32 changes: 0 additions & 32 deletions expenses/migrations/0001_initial.py

This file was deleted.

18 changes: 0 additions & 18 deletions expenses/migrations/0002_expense_currency.py

This file was deleted.

18 changes: 0 additions & 18 deletions expenses/migrations/0003_alter_expense_currency.py

This file was deleted.

Empty file removed expenses/migrations/__init__.py
Empty file.
6 changes: 3 additions & 3 deletions expenses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'}"
99 changes: 65 additions & 34 deletions expenses/templates/expenses/add_expense.html
Original file line number Diff line number Diff line change
@@ -1,40 +1,71 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Add Expense</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 min-h-screen flex items-center justify-center">
<link
href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css"
rel="stylesheet"
/>
</head>
<body class="bg-gray-100 min-h-screen flex items-center justify-center">
<div class="bg-white p-8 rounded-lg shadow-lg w-full max-w-md">
<h2 class="text-2xl font-bold mb-6 text-center">Add Expense</h2>
<form method="POST" class="space-y-4">
{% csrf_token %}
<div>
<label for="date" class="block text-gray-700">Date:</label>
<input type="date" id="date" name="date" class="w-full p-2 border border-gray-300 rounded mt-1">
</div>
<div>
<label for="category" class="block text-gray-700">Category:</label>
<input type="text" id="category" name="category" class="w-full p-2 border border-gray-300 rounded mt-1" placeholder="e.g., Food, Transportation">
</div>
<div>
<label for="amount" class="block text-gray-700">Amount:</label>
<input type="number" id="amount" name="amount" step="0.01" class="w-full p-2 border border-gray-300 rounded mt-1" placeholder="e.g., 10.50">
</div>

<div>
<label for="currency" class="block text-gray-700">Currency:</label>
<input type="text" id="currency" name="currency" class="w-full p-2 border border-gray-300 rounded mt-1" placeholder="e.g., USD, EUR (optional)">
</div>

<button type="submit" class="w-full bg-blue-500 text-white p-2 rounded mt-4 hover:bg-blue-600">Add</button>
</form>
<a href="{% url 'index' %}" class="block text-center text-blue-500 mt-4">Back to Expense Tracker</a>
</div>
<h2 class="text-2xl font-bold mb-6 text-center">Add Expense</h2>
<form method="POST" class="space-y-4">
{% csrf_token %}
<div>
<label for="date" class="block text-gray-700">Date:</label>
<input
type="date"
id="date"
name="date"
class="w-full p-2 border border-gray-300 rounded mt-1"
/>
</div>
<div>
<label for="category" class="block text-gray-700">Category:</label>
<input
type="text"
id="category"
name="category"
class="w-full p-2 border border-gray-300 rounded mt-1"
placeholder="e.g., Food, Transportation"
/>
</div>
<div>
<label for="amount" class="block text-gray-700">Amount:</label>
<input
type="number"
id="amount"
name="amount"
step="0.01"
class="w-full p-2 border border-gray-300 rounded mt-1"
placeholder="e.g., 10.50"
/>
</div>

</body>
<div>
<label for="currency" class="block text-gray-700">Currency:</label>
<input
type="text"
id="currency"
name="currency"
class="w-full p-2 border border-gray-300 rounded mt-1"
placeholder="e.g., USD, EUR (optional)"
/>
</div>

</html>
<button
type="submit"
class="w-full bg-blue-500 text-white p-2 rounded mt-4 hover:bg-blue-600"
>
Add
</button>
</form>
<a href="{% url 'index' %}" class="block text-center text-blue-500 mt-4"
>Back to Expense Tracker</a
>
</div>
</body>
</html>
102 changes: 68 additions & 34 deletions expenses/templates/expenses/edit_expense.html
Original file line number Diff line number Diff line change
@@ -1,40 +1,74 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Edit Expense</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 min-h-screen flex items-center justify-center">
<link
href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css"
rel="stylesheet"
/>
</head>
<body class="bg-gray-100 min-h-screen flex items-center justify-center">
<div class="bg-white p-8 rounded-lg shadow-lg w-full max-w-md">
<h2 class="text-2xl font-bold mb-6 text-center">Edit Expense</h2>
<form method="POST" class="space-y-4">
{% csrf_token %}
<div>
<label for="date" class="block text-gray-700">Date:</label>
<input type="date" id="date" name="date" value="{{ form.date.value|date:'Y-m-d' }}" class="w-full p-2 border border-gray-300 rounded mt-1">
</div>
<div>
<label for="category" class="block text-gray-700">Category:</label>
<input type="text" id="category" name="category" value="{{ form.category.value }}" class="w-full p-2 border border-gray-300 rounded mt-1" placeholder="e.g., Food, Transportation">
</div>
<div>
<label for="amount" class="block text-gray-700">Amount:</label>
<input type="number" id="amount" name="amount" step="0.01" value="{{ form.amount.value }}" class="w-full p-2 border border-gray-300 rounded mt-1" placeholder="e.g., 10.50">
</div>

<div>
<label for="currency" class="block text-gray-700">Currency:</label>
<input type="text" id="currency" name="currency" class="w-full p-2 border border-gray-300 rounded mt-1" placeholder="e.g., USD, EUR (optional)">
</div>

<button type="submit" class="w-full bg-blue-500 text-white p-2 rounded mt-4 hover:bg-blue-600">Save Changes</button>
</form>
<a href="{% url 'index' %}" class="block text-center text-blue-500 mt-4">Back to Expense Tracker</a>
</div>
<h2 class="text-2xl font-bold mb-6 text-center">Edit Expense</h2>
<form method="POST" class="space-y-4">
{% csrf_token %}
<div>
<label for="date" class="block text-gray-700">Date:</label>
<input
type="date"
id="date"
name="date"
value="{{ form.date.value|date:'Y-m-d' }}"
class="w-full p-2 border border-gray-300 rounded mt-1"
/>
</div>
<div>
<label for="category" class="block text-gray-700">Category:</label>
<input
type="text"
id="category"
name="category"
value="{{ form.category.value }}"
class="w-full p-2 border border-gray-300 rounded mt-1"
placeholder="e.g., Food, Transportation"
/>
</div>
<div>
<label for="amount" class="block text-gray-700">Amount:</label>
<input
type="number"
id="amount"
name="amount"
step="0.01"
value="{{ form.amount.value }}"
class="w-full p-2 border border-gray-300 rounded mt-1"
placeholder="e.g., 10.50"
/>
</div>

</body>
<div>
<label for="currency" class="block text-gray-700">Currency:</label>
<input
type="text"
id="currency"
name="currency"
class="w-full p-2 border border-gray-300 rounded mt-1"
placeholder="e.g., USD, EUR (optional)"
/>
</div>

</html>
<button
type="submit"
class="w-full bg-blue-500 text-white p-2 rounded mt-4 hover:bg-blue-600"
>
Save Changes
</button>
</form>
<a href="{% url 'index' %}" class="block text-center text-blue-500 mt-4"
>Back to Expense Tracker</a
>
</div>
</body>
</html>
Loading

0 comments on commit 10ed465

Please sign in to comment.