from django.shortcuts import render
from rest_framework import generics
from .models import News
from .serializers import NewsSerializer
# Create your views here.


class NewsList(generics.ListAPIView):
    serializer_class = NewsSerializer
    def get_queryset(self): # Override query_set if a community is passed in as a query param.
        
        queryset = News.objects.all()
        community = self.request.query_params.get('community')
        if community is not None:
            queryset = queryset.filter(community=community)
        return queryset

