Coverage for tasks/models.py: 100.00%

28 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-11 15:56 -0700

1from django.contrib.auth import get_user_model 1a

2from django.db import models 1a

3from django.urls import reverse 1a

4from django.utils import timezone 1a

5 

6 

7def one_week_hence(): 1a

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

9 

10 

11class ToDoList(models.Model): 1a

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

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

14 owner = models.ForeignKey( 1a

15 get_user_model(), 

16 default=1, 

17 on_delete=models.CASCADE, 

18 ) 

19 

20 class Meta: 1a

21 ordering = ["date"] 1a

22 

23 def __str__(self): 1a

24 return self.title 1b

25 

26 def get_absolute_url(self): 1a

27 return reverse("list", args=[self.id]) 1c

28 

29 

30class ToDoItem(models.Model): 1a

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

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

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

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

35 todo_list = models.ForeignKey( 1a

36 ToDoList, 

37 on_delete=models.CASCADE, 

38 ) 

39 

40 class Meta: 1a

41 ordering = ["due_date"] 1a

42 

43 def __str__(self): 1a

44 return f"{self.title}: due {self.due_date}" 1d

45 

46 def get_absolute_url(self): 1a

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