Rewrite schema generation (#1)
* Completeley rewritten schema generation * Added support for python 2.7 and 3.4 * Restructured testing and build configuration * Added nested request schemas This rewrite completely replaces the public interface of the django rest schema generation library, so further changes will be needed to re-enable and further extend the customization points one might want.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
from django.contrib.auth.models import User
|
||||
from rest_framework import serializers
|
||||
|
||||
from snippets.models import Snippet
|
||||
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
snippets = serializers.PrimaryKeyRelatedField(many=True, queryset=Snippet.objects.all())
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('id', 'username', 'snippets')
|
||||
@@ -0,0 +1,8 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from users import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.UserList.as_view()),
|
||||
url(r'^(?P<pk>[0-9]+)/$', views.user_detail),
|
||||
]
|
||||
@@ -0,0 +1,24 @@
|
||||
from django.contrib.auth.models import User
|
||||
from rest_framework.decorators import api_view
|
||||
from rest_framework.generics import get_object_or_404
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from users.serializers import UserSerializer
|
||||
|
||||
|
||||
class UserList(APIView):
|
||||
"""UserList cbv classdoc"""
|
||||
|
||||
def get(self, request):
|
||||
queryset = User.objects.all()
|
||||
serializer = UserSerializer(queryset, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def user_detail(request, pk):
|
||||
"""user_detail fbv docstring"""
|
||||
user = get_object_or_404(User.objects, pk=pk)
|
||||
serializer = UserSerializer(user)
|
||||
return Response(serializer.data)
|
||||
Reference in New Issue
Block a user