How Django taught me more than just CRUD and gave me a framework for thinking like a builder.
The Beginning
When I first ran django-admin startproject
, I had no idea I was entering a full-blown ecosystem. I thought I’d be stitching together a few forms and models turns out I was architecting a universe.
Here’s how I got from zero to a functional Django app and why CRUD was just the appetizer.
Step-by-Step Build
1. Setting Up the Skeleton
django-admin startproject expense_tracker
cd expense_tracker
python manage.py startapp transactions
Key decisions:
- I chose a project name that reflected real utility “Expense Tracker” because I wanted my learning to feel practical.
- Started with a single app for clean scope.
2. Building Models First
Inside transactions/models.py
:
from django.db import models
class Expense(models.Model):
name = models.CharField(max_length=100)
amount = models.DecimalField(max_digits=10, decimal_places=2)
date = models.DateField()
def __str__(self):
return f"{self.name}: {self.amount}"
What I learned:
Django’s ORM makes database tables feel intuitive.
Modeling isn’t just technical it’s philosophical. What does an “expense” mean in my world?
3. Migrating and Admin Setup
python manage.py makemigrations
python manage.py migrate
Then in transactions/admin.py
:
from django.contrib import admin
from .models import Expense
admin.site.register(Expense)
Suddenly I had a beautiful admin panel. It felt like cheating in the best way.
4. Views, Forms, and Templates
Function-based views were my go-to:
def add_expense(request):
if request.method == "POST":
form = ExpenseForm(request.POST)
if form.is_valid():
form.save()
return redirect("list_expenses")
else:
form = ExpenseForm()
return render(request, "add.html", {"form": form})
Aha moments:
POST vs GET finally made sense once I wired them into views.
Forms gave me a crash course in validation and user experience
5. URLs and App Routing
In transactions/urls.py
:
from django.urls import path
from . import views
urlpatterns = [
path("add/", views.add_expense, name="add_expense"),
path("", views.list_expenses, name="list_expenses"),
]
Then I included this in the main project’s urls.py
:
path("expenses/", include("transactions.urls")),
Modular routing hit home here it felt like Django was teaching me how to design scalable software.
Lessons From My First Django App
- The admin panel is more than a dashboard it’s a real tool for feedback and iteration.
- Views and forms are where UX and logic shake hands.
- Modular thinking starts early, even in urls.py.
Top comments (0)