Spaces:
Sleeping
Sleeping
Create models.py
Browse files
models.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dataclasses import dataclass, asdict
|
| 2 |
+
from typing import List, Dict, Any, Optional
|
| 3 |
+
import uuid
|
| 4 |
+
|
| 5 |
+
@dataclass
|
| 6 |
+
class Profile:
|
| 7 |
+
id: str
|
| 8 |
+
username: str
|
| 9 |
+
offers: List[str]
|
| 10 |
+
wants: List[str]
|
| 11 |
+
availability: str
|
| 12 |
+
preferences: str
|
| 13 |
+
avatar: Optional[str] = None
|
| 14 |
+
|
| 15 |
+
@staticmethod
|
| 16 |
+
def from_dict(d: Dict[str, Any]) -> "Profile":
|
| 17 |
+
return Profile(
|
| 18 |
+
id=str(d.get("id") or uuid.uuid4()),
|
| 19 |
+
username=str(d.get("username") or "").strip(),
|
| 20 |
+
offers=list(d.get("offers") or []),
|
| 21 |
+
wants=list(d.get("wants") or []),
|
| 22 |
+
availability=str(d.get("availability") or ""),
|
| 23 |
+
preferences=str(d.get("preferences") or ""),
|
| 24 |
+
avatar=d.get("avatar"),
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
def to_dict(self) -> Dict[str, Any]:
|
| 28 |
+
return asdict(self)
|