📝 Few small improvements
This commit is contained in:
parent
42f7713345
commit
20a826e8c0
1 changed files with 21 additions and 2 deletions
23
README.md
23
README.md
|
|
@ -242,7 +242,7 @@ from ohmyapi_auth import (
|
|||
|
||||
from .models import Tournament
|
||||
|
||||
router = APIRouter(prefix="/tournament")
|
||||
router = APIRouter(prefix="/tournament", tags=["Tournament"])
|
||||
|
||||
|
||||
@router.get("/")
|
||||
|
|
@ -260,10 +260,11 @@ Use Tortoise's `Manager` to implement model-level permissions.
|
|||
|
||||
```python
|
||||
from ohmyapi.db import Manager
|
||||
from ohmyapi_auth.models import User
|
||||
|
||||
|
||||
class TeamManager(Manager):
|
||||
async def for_user(self, user: ohmyapi_auth.models.User):
|
||||
async def for_user(self, user: User):
|
||||
return await self.filter(members=user).all()
|
||||
|
||||
|
||||
|
|
@ -274,6 +275,24 @@ class Team(Model):
|
|||
manager = TeamManager()
|
||||
```
|
||||
|
||||
Use the custom manager in your FastAPI route handler:
|
||||
|
||||
```python
|
||||
from ohmyapi.router import APIRouter
|
||||
from ohmyapi_auth import (
|
||||
models as auth,
|
||||
permissions,
|
||||
)
|
||||
|
||||
router = APIRouter(prefix="/tournament", tags=["Tournament"])
|
||||
|
||||
|
||||
@router.get("/teams")
|
||||
async def teams(user: auth.User = Depends(permissions.require_authenticated)):
|
||||
queryset = Team.for_user(user)
|
||||
return await Tournament.Schema.many.from_queryset(queryset)
|
||||
```
|
||||
|
||||
## Shell
|
||||
|
||||
Similar to Django, you can attach to an interactive shell with your project already loaded inside.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue