📝 Use field.data.UUIDField as id in examples
This commit is contained in:
parent
812049eae7
commit
c15bc82caa
1 changed files with 16 additions and 10 deletions
26
README.md
26
README.md
|
|
@ -1,25 +1,31 @@
|
|||
# OhMyAPI
|
||||
|
||||
> Think: Micro-Django, but API-first, less clunky and 100% async.
|
||||
> Think: Django RestFramework, but less clunky and 100% async.
|
||||
|
||||
OhMyAPI is a Django-flavored web-application scaffolding framework and management layer.
|
||||
Built around FastAPI and TortoiseORM, it is 100% async.
|
||||
|
||||
It is ***blazingly fast***, ***fun*** to use and comes with ***batteries included***!
|
||||
It is ***blazingly fast***, ***fun to use*** and comes with ***batteries included***!
|
||||
|
||||
**Features**
|
||||
|
||||
- Django-like project-layout and -structure
|
||||
- Django-like prject-level settings.py
|
||||
- Django-like project-level settings.py
|
||||
- Django-like models via TortoiseORM
|
||||
- Django-like `Model.Meta` class for model configuration
|
||||
- Easily convert your query results to `pydantic` models via `Model.Schema`
|
||||
- Django-like migrations (makemigrations & migrate) via Aerich
|
||||
- Django-like migrations (`makemigrations` & `migrate`) via Aerich
|
||||
- Django-like CLI tooling (`startproject`, `startapp`, `shell`, `serve`, etc)
|
||||
- Various optional builtin apps you can hook into your project
|
||||
- Highly configurable and customizable
|
||||
- 100% async
|
||||
|
||||
OhMyAPI aims to:
|
||||
|
||||
- combine FastAPI, TortoiseORM and Aerich migrations into a high-productivity web-application framework
|
||||
- tying everything neatly together into a project structure consisting of apps with models and a router
|
||||
- while ***AVOIDING*** to introduce any additional abstractions ontop of Tortoise's model-system or FastAPI's routing
|
||||
|
||||
---
|
||||
|
||||
## Getting started
|
||||
|
|
@ -82,7 +88,7 @@ from ohmyapi.db import Model, field
|
|||
|
||||
|
||||
class Tournament(Model):
|
||||
id = field.IntField(primary_key=True)
|
||||
id = field.data.UUIDField(primary_key=True)
|
||||
name = field.TextField()
|
||||
created = field.DatetimeField(auto_now_add=True)
|
||||
|
||||
|
|
@ -91,7 +97,7 @@ class Tournament(Model):
|
|||
|
||||
|
||||
class Event(Model):
|
||||
id = field.IntField(primary_key=True)
|
||||
id = field.data.UUIDField(primary_key=True)
|
||||
name = field.TextField()
|
||||
tournament = field.ForeignKeyField('tournament.Tournament', related_name='events')
|
||||
participants = field.ManyToManyField('torunament.Team', related_name='events', through='event_team')
|
||||
|
|
@ -103,7 +109,7 @@ class Event(Model):
|
|||
|
||||
|
||||
class Team(Model):
|
||||
id = field.IntField(primary_key=True)
|
||||
id = field.data.UUIDField(primary_key=True)
|
||||
name = field.TextField()
|
||||
|
||||
def __str__(self):
|
||||
|
|
@ -130,7 +136,7 @@ async def list():
|
|||
|
||||
|
||||
@router.get("/:id")
|
||||
async def get(id: int):
|
||||
async def get(id: str):
|
||||
try:
|
||||
queryset = Tournament.get(pk=id)
|
||||
return await Tournament.Schema.one(queryset)
|
||||
|
|
@ -257,7 +263,7 @@ async def list(user: auth.User = Depends(permissions.require_authenticated)):
|
|||
|
||||
### Model-Level Permissions
|
||||
|
||||
Use Tortoise's `Manager` to implement model-layer permissions.
|
||||
Use Tortoise's `Manager` to implement model-level permissions.
|
||||
|
||||
```python
|
||||
from ohmyapi.db import Manager
|
||||
|
|
@ -265,7 +271,7 @@ from typing import Callable
|
|||
|
||||
|
||||
class TeamManager(Manager):
|
||||
async def for_user(self, user):
|
||||
async def for_user(self, user: ohmyapi_auth.models.User):
|
||||
return await self.filter(members=user).all()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue