Async REST framework for tortoise-orm and starlette
- python>=3.6
- starlette
- tortoise-orm
pip install kame
Having the following tortoise model:
from tortoise.models import Model
from tortoise import fields
class Tour(Model):
id = fields.IntField(pk=True)
name = fields.TextField()
data = fields.JSONField(default=dict)
def __str__(self):
return self.name
- Create a serializer
from kame import serializers
class TourSerializer(serializers.ModelSerializer):
class Meta:
model = Tour
fields = ['id', 'name', 'description', 'parent', 'active', 'image', 'descendant_ids']
- Create a viewset
from kame import viewsets
class TourViewSet(viewsets.ModelViewSet):
queryset = Tour.all
serializer_class = TourSerializer
- Register a route
from kame import routers
router = routers.DefaultRouter()
router.register('/tours', TourViewSet, basename="tour")