From 4e1feddb454a9df91c2e323bdb4e6d1ae1ea304f Mon Sep 17 00:00:00 2001 From: Disco DeDisco Date: Sun, 8 Feb 2026 22:50:03 -0500 Subject: [PATCH] new name @property in List model, replete w. proper testing in tests.test_models --- src/apps/dashboard/models.py | 4 ++++ src/apps/dashboard/tests/test_models.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/apps/dashboard/models.py b/src/apps/dashboard/models.py index a439ace..768b0ea 100644 --- a/src/apps/dashboard/models.py +++ b/src/apps/dashboard/models.py @@ -10,6 +10,10 @@ class List(models.Model): on_delete=models.CASCADE, ) + @property + def name(self): + return self.item_set.first().text + def get_absolute_url(self): return reverse("view_list", args=[self.id]) diff --git a/src/apps/dashboard/tests/test_models.py b/src/apps/dashboard/tests/test_models.py index 0ac4457..1ef27ae 100644 --- a/src/apps/dashboard/tests/test_models.py +++ b/src/apps/dashboard/tests/test_models.py @@ -68,3 +68,9 @@ class ListModelTest(TestCase): def test_list_owner_is_optional(self): List.objects.create() + + def test_list_name_is_first_item_text(self): + list_ = List.objects.create() + Item.objects.create(list=list_, text="first item") + Item.objects.create(list=list_, text="second item") + self.assertEqual(list_.name, "first item")