📝 Reflect latest changes
This commit is contained in:
parent
3465ec71c7
commit
30a7826eeb
1 changed files with 20 additions and 12 deletions
32
README.md
32
README.md
|
|
@ -86,31 +86,35 @@ Write your first model in `turnament/models.py`:
|
||||||
```python
|
```python
|
||||||
from ohmyapi.db import Model, field
|
from ohmyapi.db import Model, field
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
from decimal import Decimal
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
|
||||||
class Tournament(Model):
|
class Tournament(Model):
|
||||||
id = field.data.UUIDField(primary_key=True)
|
id: UUID = field.data.UUIDField(primary_key=True)
|
||||||
name = field.TextField()
|
name: str = field.TextField()
|
||||||
created = field.DatetimeField(auto_now_add=True)
|
created: datetime = field.DatetimeField(auto_now_add=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Event(Model):
|
class Event(Model):
|
||||||
id = field.data.UUIDField(primary_key=True)
|
id: UUID = field.data.UUIDField(primary_key=True)
|
||||||
name = field.TextField()
|
name: str = field.TextField()
|
||||||
tournament = field.ForeignKeyField('tournament.Tournament', related_name='events')
|
tournament: UUID = field.ForeignKeyField('tournament.Tournament', related_name='events')
|
||||||
participants = field.ManyToManyField('tournament.Team', related_name='events', through='event_team')
|
participants: field.ManyToManyRelation[Team] = field.ManyToManyField('tournament.Team', related_name='events', through='event_team')
|
||||||
modified = field.DatetimeField(auto_now=True)
|
modified: datetime = field.DatetimeField(auto_now=True)
|
||||||
prize = field.DecimalField(max_digits=10, decimal_places=2, null=True)
|
prize: Decimal = field.DecimalField(max_digits=10, decimal_places=2, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Team(Model):
|
class Team(Model):
|
||||||
id = field.data.UUIDField(primary_key=True)
|
id: UUID = field.data.UUIDField(primary_key=True)
|
||||||
name = field.TextField()
|
name: str = field.TextField()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
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:
|
You can use the models as `ForeignKeyField` in your application models:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
from ohmyapi.db import Model, field
|
||||||
|
from ohmyapi_auth.models import User
|
||||||
|
|
||||||
|
|
||||||
class Team(Model):
|
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')
|
||||||
[...]
|
[...]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue