<gh_stars>0
from rest_framework import filters
from rest_framework import viewsets

from logbook.models import Message, Category, Attachment
from logbook.serializers import MessageSerializer, CategorySerializer, AttachmentSerializer


class AttachmentViewSet(viewsets.ReadOnlyModelViewSet):
    """
    API endpoint that allows Files to be viewed.
    """

    queryset = Attachment.objects.all().order_by("-created_at")
    serializer_class = AttachmentSerializer


class MessageViewSet(viewsets.ReadOnlyModelViewSet):
    """
    API endpoint that allows Messages to be viewed.

    **Search fields:** summary, description
    """

    queryset = Message.objects.all().order_by("-time")
    serializer_class = MessageSerializer
    filter_backends = [filters.SearchFilter]
    search_fields = ["text"]


class CategoryViewSet(viewsets.ReadOnlyModelViewSet):
    """
    API endpoint that allows Categories to be viewed.

    **Search fields:** keywords, model
    """

    queryset = Category.objects.all().order_by("type")
    serializer_class = CategorySerializer
    filter_backends = [filters.SearchFilter]
    search_fields = ["keywords", "type"]

from rest_framework import filters
from rest_framework import viewsets

from logbook.models import Message, Category, Attachment
from logbook.serializers import MessageSerializer, CategorySerializer, AttachmentSerializer


class AttachmentViewSet(viewsets.ReadOnlyModelViewSet):
    """
    API endpoint that allows Files to be viewed.
    """

    queryset = Attachment.objects.all().order_by("-created_at")
    serializer_class = AttachmentSerializer


class MessageViewSet(viewsets.ReadOnlyModelViewSet):
    """
    API endpoint that allows Messages to be viewed.

    **Search fields:** summary, description
    """

    queryset = Message.objects.all().order_by("-time")
    serializer_class = MessageSerializer
    filter_backends = [filters.SearchFilter]
    search_fields = ["text"]


class CategoryViewSet(viewsets.ReadOnlyModelViewSet):
    """
    API endpoint that allows Categories to be viewed.

    **Search fields:** keywords, model
    """

    queryset = Category.objects.all().order_by("type")
    serializer_class = CategorySerializer
    filter_backends = [filters.SearchFilter]
    search_fields = ["keywords", "type"]
API endpoint that allows Files to be viewed. API endpoint that allows Messages to be viewed.      **Search fields:** summary, description API endpoint that allows Categories to be viewed.      **Search fields:** keywords, model