Commit f5011573 authored by alexandre's avatar alexandre

Faster and lighter Score list API

parent 9935f780
......@@ -17,5 +17,15 @@ class ScoreSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Score
#fields = ('id', 'title', 'stage_set', 'mainline')
fields = '__all__'
class ScoreLightSerializer(serializers.HyperlinkedModelSerializer):
"""A serializer exposing just a subsets of field when we don't need the full
representation.
"""
id = serializers.ReadOnlyField()
class Meta:
model = Score
fields = ('id', 'title', 'created_at', 'updated_at')
......@@ -5,7 +5,7 @@ from rest_framework.parsers import FormParser, MultiPartParser
from rest_framework.filters import OrderingFilter, SearchFilter
# from django_filters.rest_framework import DjangoFilterBackend
from .models import Attachment, Score
from .serializers import AttachmentSerializer, ScoreSerializer
from .serializers import AttachmentSerializer, ScoreSerializer, ScoreLightSerializer
......@@ -29,10 +29,18 @@ class ScoreViewSet(viewsets.ModelViewSet):
API endpoint that allows users to be viewed or edited.
"""
queryset = Score.objects.all()
serializer_class = ScoreSerializer
pagination_class = ScoreViewSetPagination
filter_backends = (OrderingFilter, SearchFilter)
search_fields = ('title',)
def get_serializer_class(self, *args, **kwargs):
"""
Expose a lighter set of fields when a list is required
"""
if self.action == 'list':
return ScoreLightSerializer
else:
return ScoreSerializer
class ScoreView(TemplateView):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment