
from django.utils import timezone

from rest_framework import status, mixins
from rest_framework.authentication import TokenAuthentication, BasicAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import detail_route, list_route
from rest_framework.response import Response
from rest_framework import viewsets

from news_event.models import News, Event
from news_event.serializers import NewsSerializer, EventSerializer 


class NewsViewSet(viewsets.ModelViewSet):
    
    queryset = News.objects.all()
    serializer_class = NewsSerializer
    

class EventViewSet(viewsets.ModelViewSet):
    
    queryset = Event.objects.all()
    serializer_class = EventSerializer
    
    



from django.utils import timezone

from rest_framework import status, mixins
from rest_framework.authentication import TokenAuthentication, BasicAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import detail_route, list_route
from rest_framework.response import Response
from rest_framework import viewsets

from news_event.models import News, Event
from news_event.serializers import NewsSerializer, EventSerializer 


class NewsViewSet(mixins.ListModelMixin,
                mixins.RetrieveModelMixin,
                mixins.CreateModelMixin,
                viewsets.GenericViewSet):
    
    queryset = News.objects.all()
    serializer_class = NewsSerializer
    

class EventViewSet(mixins.ListModelMixin,
                mixins.RetrieveModelMixin,
                mixins.CreateModelMixin,
                viewsets.GenericViewSet):
    
    queryset = Event.objects.all()
    serializer_class = EventSerializer
    
    


Switch from modelviewset to mixins
Switch from modelviewset to mixins

  
  from django.utils import timezone
  
  from rest_framework import status, mixins
  from rest_framework.authentication import TokenAuthentication, BasicAuthentication
  from rest_framework.permissions import IsAuthenticated
  from rest_framework.decorators import detail_route, list_route
  from rest_framework.response import Response
  from rest_framework import viewsets
  
  from news_event.models import News, Event
  from news_event.serializers import NewsSerializer, EventSerializer 
  
  
- class NewsViewSet(viewsets.ModelViewSet):
+ class NewsViewSet(mixins.ListModelMixin,
+                 mixins.RetrieveModelMixin,
+                 mixins.CreateModelMixin,
+                 viewsets.GenericViewSet):
      
      queryset = News.objects.all()
      serializer_class = NewsSerializer
      
  
- class EventViewSet(viewsets.ModelViewSet):
+ class EventViewSet(mixins.ListModelMixin,
+                 mixins.RetrieveModelMixin,
+                 mixins.CreateModelMixin,
+                 viewsets.GenericViewSet):
      
      queryset = Event.objects.all()
      serializer_class = EventSerializer
      
      
  
  
Switch from modelviewset to mixins
## Code Before:

from django.utils import timezone

from rest_framework import status, mixins
from rest_framework.authentication import TokenAuthentication, BasicAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import detail_route, list_route
from rest_framework.response import Response
from rest_framework import viewsets

from news_event.models import News, Event
from news_event.serializers import NewsSerializer, EventSerializer 


class NewsViewSet(viewsets.ModelViewSet):
    
    queryset = News.objects.all()
    serializer_class = NewsSerializer
    

class EventViewSet(viewsets.ModelViewSet):
    
    queryset = Event.objects.all()
    serializer_class = EventSerializer
    
    


## Instruction:
Switch from modelviewset to mixins
## Code After:

from django.utils import timezone

from rest_framework import status, mixins
from rest_framework.authentication import TokenAuthentication, BasicAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import detail_route, list_route
from rest_framework.response import Response
from rest_framework import viewsets

from news_event.models import News, Event
from news_event.serializers import NewsSerializer, EventSerializer 


class NewsViewSet(mixins.ListModelMixin,
                mixins.RetrieveModelMixin,
                mixins.CreateModelMixin,
                viewsets.GenericViewSet):
    
    queryset = News.objects.all()
    serializer_class = NewsSerializer
    

class EventViewSet(mixins.ListModelMixin,
                mixins.RetrieveModelMixin,
                mixins.CreateModelMixin,
                viewsets.GenericViewSet):
    
    queryset = Event.objects.all()
    serializer_class = EventSerializer
    
    

