Coverage for tasks/models.py: 100.00%

29 statements  

« prev     ^ index     » next       coverage.py v7.17.5, created at 2026-11-28 11:01 -0800

1from typing import ClassVar 1a

2 

3from django.contrib.auth import get_user_model 1a

4from django.db import models 1a

5from django.urls import reverse 1a

6from django.utils import timezone 1a

7 

8 

9def one_week_hence(): 1a

10 return timezone.now() + timezone.timedelta(days=7) 1a

11 

12 

13class ToDoList(models.Model): 1a

14 title = models.CharField(max_length=100, unique=True) 1a

15 date = models.DateTimeField(auto_now_add=True) 1a

16 owner = models.ForeignKey( 1a

17 get_user_model(), 

18 default=1, 

19 on_delete=models.CASCADE, 

20 ) 

21 

22 class Meta: 1a

23 ordering: ClassVar[list[str]] = ["date"] 1a

24 

25 def __str__(self): 1a

26 return self.title 1a

27 

28 def get_absolute_url(self): 1a

29 return reverse("list", args=[self.id]) 1a

30 

31 

32class ToDoItem(models.Model): 1a

33 title = models.CharField(max_length=100) 1a

34 description = models.TextField(blank=True) 1a

35 created_date = models.DateTimeField(auto_now_add=True) 1a

36 due_date = models.DateTimeField(default=one_week_hence) 1a

37 todo_list = models.ForeignKey( 1a

38 ToDoList, 

39 on_delete=models.CASCADE, 

40 ) 

41 

42 class Meta: 1a

43 ordering: ClassVar[list[str]] = ["due_date"] 1a

44 

45 def __str__(self): 1a

46 return f"{self.title}: due {self.due_date}" 1a

47 

48 def get_absolute_url(self): 1a

49 return reverse("item-update", args=[str(self.todo_list.id), str(self.id)]) 1a