create settings module in preparation of aerich
currently, it's only used for tortoise_orm
This commit is contained in:
parent
be0d7acf3b
commit
6c6ca0e997
2 changed files with 23 additions and 8 deletions
|
|
@ -18,6 +18,8 @@ from textual.widgets import (
|
|||
)
|
||||
from tortoise import Tortoise
|
||||
|
||||
from teilchensammler_cli import settings
|
||||
|
||||
|
||||
@final
|
||||
class SearchBar(Static):
|
||||
|
|
@ -43,9 +45,7 @@ class SearchBar(Static):
|
|||
id="teilchen-input",
|
||||
type="text",
|
||||
)
|
||||
yield Button(
|
||||
"Add", variant="success", classes="search-bar-buttons", id="button-add"
|
||||
)
|
||||
yield Button("Add", variant="success", classes="search-bar-buttons", id="button-add")
|
||||
yield Button(
|
||||
"Search",
|
||||
variant="default",
|
||||
|
|
@ -99,13 +99,14 @@ class AddInventoryScreen(Screen[None]):
|
|||
@final
|
||||
class SammlerApp(App[None]):
|
||||
async def on_mount(self) -> None:
|
||||
await Tortoise.init(
|
||||
db_url="sqlite://db.sqlite3",
|
||||
modules={"models": ["teilchensammler_cli.models"]},
|
||||
)
|
||||
await Tortoise.generate_schemas()
|
||||
await Tortoise.init(config=settings.TORTOISE_ORM_CONFIG)
|
||||
await Tortoise.generate_schemas(safe=True)
|
||||
_ = self.push_screen(AddInventoryScreen())
|
||||
|
||||
async def on_unmount(self) -> None:
|
||||
# https://tortoise.github.io/setup.html#the-importance-of-cleaning-up
|
||||
await Tortoise.close_connections()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
app = SammlerApp()
|
||||
|
|
|
|||
14
src/teilchensammler_cli/settings.py
Normal file
14
src/teilchensammler_cli/settings.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
TORTOISE_ORM_CONFIG = {
|
||||
"connections": {
|
||||
"default": {
|
||||
"engine": "tortoise.backends.sqlite",
|
||||
"credentials": {"file_path": "db.sqlite3"},
|
||||
},
|
||||
},
|
||||
"apps": {
|
||||
"app": {
|
||||
"models": ["teilchensammer_cli.models", "aerich.models"],
|
||||
"default_connection": "default",
|
||||
}
|
||||
},
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue