Skip to content

Commit 964fa73

Browse files
committed
Work in progress
1 parent e390e47 commit 964fa73

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

python-mixins/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
# TODO
22

33
This folder contains the source code that accompanies the Real Python tutorial, [TODO](TODO).
4+
5+
## Usage
6+
7+
```shell
8+
$ DATABASE=database.db python main.py
9+
```

python-mixins/TODO.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Add nullable foreign key handling
2+
- Implement examples to test and demonstrate

python-mixins/main.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import logging
2+
3+
logging.basicConfig(
4+
level=logging.DEBUG,
5+
format="\N{rocket} %(message)s"
6+
)
7+
8+
from orm import ActiveRecord, TimestampMixin, SQLMixin
9+
10+
11+
class User(ActiveRecord):
12+
first_name: str
13+
last_name: str
14+
team: bool = False
15+
16+
17+
class Tutorial(SQLMixin, ActiveRecord):
18+
author: User
19+
title: str
20+
url: str
21+
22+
23+
class Comment(TimestampMixin, SQLMixin, ActiveRecord):
24+
text: str
25+
tutorial: Tutorial
26+
user: User | None = None
27+
28+
29+
30+
def populate():
31+
user = User("Joanna", "Jablonski", team=True)
32+
user.save()
33+
34+
tutorial = Tutorial(
35+
author=user,
36+
url="https://realpython.com/python-f-strings/",
37+
title="Python's F-String for String Interpolation and Formatting",
38+
)
39+
tutorial.save()
40+
41+
comment = Comment(
42+
text="A neutral comment from an anonymous reader",
43+
tutorial=tutorial,
44+
)
45+
comment.save()
46+
47+
48+
if __name__ == "__main__":
49+
populate()

0 commit comments

Comments
 (0)