-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
35 lines (28 loc) · 761 Bytes
/
models.py
File metadata and controls
35 lines (28 loc) · 761 Bytes
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
from dataclasses import dataclass, field
from datetime import datetime, timedelta
from typing import List, Optional
def generate_id(): # closures
id = 0
def increment_id() -> int:
nonlocal id
id += 1
return id
return increment_id
factory_id = generate_id()
@dataclass
class User:
username: str = ''
@dataclass
class Event:
title: str
starts_at: datetime
ends_at: datetime
max_attendees: int = field(default=0)
created_at: datetime = field(default_factory=lambda: datetime.now())
attendees: List[User] = field(default_factory=list)
is_public: bool = field(default_factory=bool)
id: int = field(default_factory=factory_id)
@dataclass
class Enrollment:
user: User
event: Event