django-serializer packaged and delivered via pypi
pip install django-serializer
Serialization provided by marshmallow. The library provide generic and custom CRUD views and paginators. Automatic swagger generation provided by apispec
See HISTORY.md
from django_serializer.v2.serializer import ModelSerializer
from django_serializer.v2.views import ApiView
from myapp.models import MyModel
class MyModelSerializer(ModelSerializer):
class SMeta:
model = MyModel
fields = ('id', 'foo', 'bar')
class MyView(ApiView):
class Meta:
serializer = MyModelSerializer
def execute(self, request, *args, **kwargs):
return MyModel.objects.first()
from django_serializer.v2.serializer import ModelSerializer
from django_serializer.v2.views import ApiView
from myapp.models import MyModel
class MyModelSerializer(ModelSerializer):
class SMeta:
model = MyModel
fields = ('id', 'foo', 'bar')
class MyListView(ApiView):
class Meta:
serializer = MyModelSerializer
serializer_many = True
def execute(self, request, *args, **kwargs):
return MyModel.objects.first()
from django import forms
from django_serializer.v2.views import ApiView
class MyQueryForm(forms.Form):
id = forms.IntegerField()
class MyListView(ApiView):
class Meta:
query_form = MyQueryForm
serializer = MyModelSerializer
serializer_many = True
def execute(self, request, *args, **kwargs):
object_id = self.request_query['id']
return MyModel.objects.filter(id=object_id).first()
# urls.py
from django_serializer.v2.swagger.views import index
from django.urls import path
urlpatterns = [
path('swagger.json', index),
]
Feel free to open pull request to the latest rc-<version>
branch.
See LICENSE