📝 Reflect latest changes

This commit is contained in:
Brian Wiborg 2025-09-28 14:52:49 +02:00
parent 3465ec71c7
commit 30a7826eeb
No known key found for this signature in database

View file

@ -86,31 +86,35 @@ Write your first model in `turnament/models.py`:
```python
from ohmyapi.db import Model, field
from datetime import datetime
from decimal import Decimal
from uuid import UUID
class Tournament(Model):
id = field.data.UUIDField(primary_key=True)
name = field.TextField()
created = field.DatetimeField(auto_now_add=True)
id: UUID = field.data.UUIDField(primary_key=True)
name: str = field.TextField()
created: datetime = field.DatetimeField(auto_now_add=True)
def __str__(self):
return self.name
class Event(Model):
id = field.data.UUIDField(primary_key=True)
name = field.TextField()
tournament = field.ForeignKeyField('tournament.Tournament', related_name='events')
participants = field.ManyToManyField('tournament.Team', related_name='events', through='event_team')
modified = field.DatetimeField(auto_now=True)
prize = field.DecimalField(max_digits=10, decimal_places=2, null=True)
id: UUID = field.data.UUIDField(primary_key=True)
name: str = field.TextField()
tournament: UUID = field.ForeignKeyField('tournament.Tournament', related_name='events')
participants: field.ManyToManyRelation[Team] = field.ManyToManyField('tournament.Team', related_name='events', through='event_team')
modified: datetime = field.DatetimeField(auto_now=True)
prize: Decimal = field.DecimalField(max_digits=10, decimal_places=2, null=True)
def __str__(self):
return self.name
class Team(Model):
id = field.data.UUIDField(primary_key=True)
name = field.TextField()
id: UUID = field.data.UUIDField(primary_key=True)
name: str = field.TextField()
def __str__(self):
return self.name
@ -210,9 +214,13 @@ It comes with a `User` and `Group` model, as well as endpoints for JWT auth.
You can use the models as `ForeignKeyField` in your application models:
```python
from ohmyapi.db import Model, field
from ohmyapi_auth.models import User
class Team(Model):
[...]
members = field.ManyToManyField('ohmyapi_auth.User', related_name='tournament_teams', through='tournament_teams')
members: field.ManyToManyRelation[User] = field.ManyToManyField('ohmyapi_auth.User', related_name='tournament_teams', through='tournament_teams')
[...]
```