new name @property in List model, replete w. proper testing in tests.test_models
This commit is contained in:
@@ -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])
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user