From 0545aee69a11f794afead1fc9605d1da2a43bf24 Mon Sep 17 00:00:00 2001 From: Andrew Zigler Date: Mon, 30 Jun 2025 14:11:44 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20implement=20note-taking=20f?= =?UTF-8?q?eature=20on=20home=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit introduces a new function to add notes and updates the home page view to display a list of notes. The home page template is also modified to show notes if available. --- pages/models.py | 8 ++++++++ pages/views.py | 7 +++++++ templates/pages/home.html | 26 ++++++++++++++++++-------- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/pages/models.py b/pages/models.py index 71a8362..2e5ed8e 100644 --- a/pages/models.py +++ b/pages/models.py @@ -1,3 +1,11 @@ from django.db import models # Create your models here. + + +def add_note(note, notes=[]): + """ + Adds a note to the notes list and returns the list. + """ + notes.append(note) + return notes diff --git a/pages/views.py b/pages/views.py index 886a2ba..1b25563 100644 --- a/pages/views.py +++ b/pages/views.py @@ -1,9 +1,16 @@ from django.views.generic import TemplateView +from .models import add_note class HomePageView(TemplateView): template_name = "pages/home.html" + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + notes = add_note("Visited home page") + context["notes"] = notes + return context + class AboutPageView(TemplateView): template_name = "pages/about.html" diff --git a/templates/pages/home.html b/templates/pages/home.html index c3b6c45..e8d1b32 100644 --- a/templates/pages/home.html +++ b/templates/pages/home.html @@ -1,11 +1,21 @@ -{% extends '_base.html' %} -{% load static %} - -{% block title %}Home page{% endblock title %} - -{% block content %} +{% extends '_base.html' %} {% load static %} {% block title %}Home page{% +endblock title %} {% block content %}
- Lithium logo + Lithium logo

A Django starter project with batteries.

-{% endblock content %} + +{% if notes %} +
+ Notes: + +
+{% endif %} {% endblock content %}