from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import viewsets

from .models import Post, FetMeeting
from .serializers import PostSerializer


class PostViewSet(viewsets.ModelViewSet):
    """
    API endpoint that allows users to be viewed or edited.
    """

    queryset = Post.objects.all().order_by("-public_date")
    serializer_class = PostSerializer
    # permission_classes = [permissions.IsAuthenticated]
    filter_backends = [DjangoFilterBackend]
    filterset_fields = ["legacy_id", "slug", "legacy_rubrik_id"]
    lookup_field = "slug"

    def pre_save(self, obj):
        obj.image = self.request.FILES.get("image")
