()
| 34 | |
| 35 | |
| 36 | async def run(): |
| 37 | await Tortoise.init(db_url="sqlite://:memory:", modules={"models": ["__main__"]}) |
| 38 | await Tortoise.generate_schemas() |
| 39 | |
| 40 | # Create objects |
| 41 | await Tournament.create(name="New Tournament") |
| 42 | await Tournament.create(name="Another") |
| 43 | await Tournament.create(name="Last Tournament") |
| 44 | |
| 45 | # Serialise it |
| 46 | tourpy = await Tournament_Pydantic_List.from_queryset(Tournament.all()) |
| 47 | |
| 48 | # As Python dict with Python objects (e.g. datetime) |
| 49 | # Note that the root element is 'root' that contains the root element. |
| 50 | print(tourpy.model_dump()) |
| 51 | # As serialised JSON (e.g. datetime is ISO8601 string representation) |
| 52 | print(tourpy.model_dump_json(indent=4)) |
| 53 | |
| 54 | |
| 55 | if __name__ == "__main__": |
no test coverage detected