-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
41 lines (35 loc) · 1.15 KB
/
Copy pathmodels.py
File metadata and controls
41 lines (35 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from __future__ import annotations
from dataclasses import dataclass, field
from datetime import date
from typing import Optional
@dataclass
class Task:
"""Represents a single todo task."""
id: int
title: str
priority: str = "Medium"
category: str = "General"
completed: bool = False
created_at: str = field(default_factory=lambda: date.today().isoformat())
due_date: Optional[str] = None
def to_dict(self) -> dict:
return {
"id": self.id,
"title": self.title,
"priority": self.priority,
"category": self.category,
"completed": self.completed,
"created_at": self.created_at,
"due_date": self.due_date,
}
@classmethod
def from_dict(cls, data: dict) -> "Task":
return cls(
id=data["id"],
title=data["title"],
priority=data.get("priority", "Medium"),
category=data.get("category", "General"),
completed=data.get("completed", False),
created_at=data.get("created_at", date.today().isoformat()),
due_date=data.get("due_date"),
)