[models] move Models into their own module
This commit is contained in:
parent
221062ead5
commit
59d668ba9c
3 changed files with 59 additions and 3 deletions
18
README.md
18
README.md
|
|
@ -11,6 +11,24 @@ Data will eventuall be stored in a SQLite database.
|
|||
uv run pytest tests.py
|
||||
```
|
||||
|
||||
## Observing the app's console
|
||||
|
||||
You will need two terminals: one for showing the console, the other to run the app.
|
||||
|
||||
Since we use uv the incantation is bit different from the official documenation:
|
||||
|
||||
In one terminal:
|
||||
|
||||
```shell
|
||||
textual console
|
||||
```
|
||||
|
||||
And in the other:
|
||||
|
||||
```shell
|
||||
uv run textual run --dev src/teilchensammler_cli/__init__.py
|
||||
```
|
||||
|
||||
## Creating a new release
|
||||
|
||||
* make code changes
|
||||
|
|
|
|||
|
|
@ -16,8 +16,7 @@ from textual.widgets import (
|
|||
Input,
|
||||
Static,
|
||||
)
|
||||
from tortoise import Tortoise, fields
|
||||
from tortoise.models import Model
|
||||
from tortoise import Tortoise
|
||||
|
||||
|
||||
@final
|
||||
|
|
@ -101,7 +100,8 @@ class AddInventoryScreen(Screen[None]):
|
|||
class SammlerApp(App[None]):
|
||||
async def on_mount(self) -> None:
|
||||
await Tortoise.init(
|
||||
db_url="sqlite://db.sqlite3", modules={"models": ["teilchensammler_cli"]}
|
||||
db_url="sqlite://db.sqlite3",
|
||||
modules={"models": ["teilchensammler_cli.models"]},
|
||||
)
|
||||
await Tortoise.generate_schemas()
|
||||
_ = self.push_screen(AddInventoryScreen())
|
||||
|
|
|
|||
38
src/teilchensammler_cli/models.py
Normal file
38
src/teilchensammler_cli/models.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
from typing import final
|
||||
|
||||
from tortoise import Model, fields
|
||||
|
||||
|
||||
@final
|
||||
class Teilchen(Model):
|
||||
name = fields.TextField()
|
||||
description = fields.TextField()
|
||||
number = fields.IntField() # validate values >= 0
|
||||
|
||||
created_at = fields.DatetimeField(auto_now_add=True)
|
||||
modified_at = fields.DatetimeField(auto_now=True)
|
||||
|
||||
tags = fields.ManyToManyField(
|
||||
"models.Tag",
|
||||
through="models.TeilchenTag",
|
||||
related_name="teilchen",
|
||||
forward_key="tag_id",
|
||||
backward_key="teilchen_id",
|
||||
)
|
||||
|
||||
|
||||
@final
|
||||
class Tag(Model):
|
||||
name = fields.CharField(max_length=20)
|
||||
|
||||
created_at = fields.DatetimeField(auto_now_add=True)
|
||||
modified_at = fields.DatetimeField(auto_now=True)
|
||||
|
||||
|
||||
@final
|
||||
class TeilchenTag(Model):
|
||||
teilchen: fields.ForeignKeyRelation[Teilchen] = fields.ForeignKeyField(
|
||||
"models.Teilchen"
|
||||
)
|
||||
tag: fields.ForeignKeyRelation[Tag] = fields.ForeignKeyField("models.Tag")
|
||||
weight = fields.IntField()
|
||||
Loading…
Add table
Add a link
Reference in a new issue