From c15bc82caaf6c3d3babca7d92f66cca4bce319c9 Mon Sep 17 00:00:00 2001 From: Brian Wiborg Date: Sat, 27 Sep 2025 15:05:38 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Use=20field.data.UUIDField=20as?= =?UTF-8?q?=20id=20in=20examples?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d42fb1d..966e66d 100644 --- a/README.md +++ b/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()