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 tortoise import Tortoise
|
||||||
|
|
||||||
|
from teilchensammler_cli import settings
|
||||||
|
|
||||||
|
|
||||||
@final
|
@final
|
||||||
class SearchBar(Static):
|
class SearchBar(Static):
|
||||||
|
|
@ -43,9 +45,7 @@ class SearchBar(Static):
|
||||||
id="teilchen-input",
|
id="teilchen-input",
|
||||||
type="text",
|
type="text",
|
||||||
)
|
)
|
||||||
yield Button(
|
yield Button("Add", variant="success", classes="search-bar-buttons", id="button-add")
|
||||||
"Add", variant="success", classes="search-bar-buttons", id="button-add"
|
|
||||||
)
|
|
||||||
yield Button(
|
yield Button(
|
||||||
"Search",
|
"Search",
|
||||||
variant="default",
|
variant="default",
|
||||||
|
|
@ -99,13 +99,14 @@ class AddInventoryScreen(Screen[None]):
|
||||||
@final
|
@final
|
||||||
class SammlerApp(App[None]):
|
class SammlerApp(App[None]):
|
||||||
async def on_mount(self) -> None:
|
async def on_mount(self) -> None:
|
||||||
await Tortoise.init(
|
await Tortoise.init(config=settings.TORTOISE_ORM_CONFIG)
|
||||||
db_url="sqlite://db.sqlite3",
|
await Tortoise.generate_schemas(safe=True)
|
||||||
modules={"models": ["teilchensammler_cli.models"]},
|
|
||||||
)
|
|
||||||
await Tortoise.generate_schemas()
|
|
||||||
_ = self.push_screen(AddInventoryScreen())
|
_ = 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:
|
def main() -> None:
|
||||||
app = SammlerApp()
|
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