Source code for superdjango.interfaces.rest.library

# Classes


[docs]class REST(object): """A utility class for collecting REST API information. .. code-block:: python # <app_name>/api/serializers.py from rest_framework import serializers from ..models import Category, Objective class CategorySerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Category fields = ( "label", "value", ) class ObjectiveSerializer(serializers.HyperlinkedModelSerializer): categories = serializers.HyperlinkedIdentityField(view_name="objectives-api-category-detail") client = serializers.HyperlinkedIdentityField(view_name="clients-api-client-detail") class Meta: model = Objective fields = ( "annual_resolved_value", "cached_percentage_complete", "categories", "client", "description", "end_date", "percentage_complete_override", "priority", "stage", "start_date", "title", ) # <app_name>/api/views.py from rest_framework import viewsets from ..models import Category, Objective from .serializers import CategorySerializer, ObjectiveSerializer class CategoryViewSet(viewsets.ModelViewSet): queryset = Category.objects.all() serializer_class = CategorySerializer class ObjectiveViewSet(viewsets.ModelViewSet): queryset = Objective.objects.all() serializer_class = ObjectiveSerializer .. code-block:: python # <app_name>/api/__init__.py from superdjango.interfaces.reset import api, REST from .views import CategoryViewSet, ObjectiveViewSet class ObjectiveREST(REST): # basename = "objectives-api" # prefix = "objectives" viewsets = [ CategoryViewSet, ObjectiveViewSet, ] api.register("objectives", ObjectiveREST) ``basename`` and ``prefix`` are optional and default to ``<app_name>-api`` and ``<app_name>`` respectively. In the example above, category detail is available at ``objectives-api-category-detail`` and objective detail at ``objectives-api-objective-detail``. """ basename = None prefix = None version = None viewsets = list()