File tree Expand file tree Collapse file tree 3 files changed +57
-0
lines changed
Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 11# TODO
22
33This 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+ ```
Original file line number Diff line number Diff line change 1+ - Add nullable foreign key handling
2+ - Implement examples to test and demonstrate
Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments