from django.shortcuts import render
from .models import Resource
from .serializers import ResourceSerializer
from rest_framework import generics


class ResourceList(generics.ListCreateAPIView):
    queryset = Resource.objects.all()
    serializer_class = ResourceSerializer


class ResourceDetail(generics.RetrieveUpdateDestroyAPIView):
    queryset = Resource.objects.all()
    serializer_class = ResourceSerializer

from django.shortcuts import render
from .models import Resource
from .serializers import ResourceSerializer
from rest_framework import generics, permissions


class ResourceList(generics.ListCreateAPIView):
    queryset = Resource.objects.all()
    serializer_class = ResourceSerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)


class ResourceDetail(generics.RetrieveUpdateDestroyAPIView):
    queryset = Resource.objects.all()
    serializer_class = ResourceSerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)

Make the API read only unless authenticated.
Make the API read only unless authenticated.

  from django.shortcuts import render
  from .models import Resource
  from .serializers import ResourceSerializer
- from rest_framework import generics
+ from rest_framework import generics, permissions
  
  
  class ResourceList(generics.ListCreateAPIView):
      queryset = Resource.objects.all()
      serializer_class = ResourceSerializer
+     permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
  
  
  class ResourceDetail(generics.RetrieveUpdateDestroyAPIView):
      queryset = Resource.objects.all()
      serializer_class = ResourceSerializer
+     permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
  
Make the API read only unless authenticated.
## Code Before:
from django.shortcuts import render
from .models import Resource
from .serializers import ResourceSerializer
from rest_framework import generics


class ResourceList(generics.ListCreateAPIView):
    queryset = Resource.objects.all()
    serializer_class = ResourceSerializer


class ResourceDetail(generics.RetrieveUpdateDestroyAPIView):
    queryset = Resource.objects.all()
    serializer_class = ResourceSerializer

## Instruction:
Make the API read only unless authenticated.
## Code After:
from django.shortcuts import render
from .models import Resource
from .serializers import ResourceSerializer
from rest_framework import generics, permissions


class ResourceList(generics.ListCreateAPIView):
    queryset = Resource.objects.all()
    serializer_class = ResourceSerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)


class ResourceDetail(generics.RetrieveUpdateDestroyAPIView):
    queryset = Resource.objects.all()
    serializer_class = ResourceSerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
