index.community/apiv1/views.py

20 lines
705 B
Python
Raw Normal View History

2018-08-26 00:32:55 +00:00
from rest_framework import viewsets
from scraper.models import Instance
2018-08-26 22:12:24 +00:00
from apiv1.serializers import InstanceListSerializer, InstanceDetailSerializer
2018-08-26 00:32:55 +00:00
class InstanceViewSet(viewsets.ModelViewSet):
2018-08-26 22:12:24 +00:00
"""API endpoint to view instances"""
lookup_value_regex = '[a-zA-Z0-9-_\.]+'
2018-08-26 00:32:55 +00:00
queryset = Instance.objects.all()
2018-08-26 22:12:24 +00:00
serializer_class = InstanceListSerializer
detail_serializer_class = InstanceDetailSerializer # this serializer also includes stats and a list of peers
2018-08-26 00:32:55 +00:00
2018-08-26 22:12:24 +00:00
def get_serializer_class(self):
if self.action == 'retrieve':
if hasattr(self, 'detail_serializer_class'):
return self.detail_serializer_class
return self.serializer_class