
from rest_framework import viewsets
from .models import AirCondition, AirAverage
from .serializers import AirAverageSerializer, AirConditionSerializer


class AirConditionViewSets(viewsets.ReadOnlyModelViewSet):
    queryset = AirCondition.objects.all().order_by('-time')[:24]    # 24 hours
    serializer_class = AirConditionSerializer

from rest_framework import viewsets
from .models import AirCondition, AirAverage
from .serializers import AirAverageSerializer, AirConditionSerializer


class AirConditionViewSets(viewsets.ReadOnlyModelViewSet):
    queryset = AirCondition.objects.all().order_by('-time')[:24]    # 24 hours
    serializer_class = AirConditionSerializer


class AirAverageViewSets(viewsets.ReadOnlyModelViewSet):
    queryset = AirAverage.objects.all().order_by('-from_time')[:10]     # 5 days
    serializer_class = AirAverageSerializer
Add pm2.5 avg view api
Add pm2.5 avg view api

  
  from rest_framework import viewsets
  from .models import AirCondition, AirAverage
  from .serializers import AirAverageSerializer, AirConditionSerializer
  
  
  class AirConditionViewSets(viewsets.ReadOnlyModelViewSet):
      queryset = AirCondition.objects.all().order_by('-time')[:24]    # 24 hours
      serializer_class = AirConditionSerializer
+ 
+ 
+ class AirAverageViewSets(viewsets.ReadOnlyModelViewSet):
+     queryset = AirAverage.objects.all().order_by('-from_time')[:10]     # 5 days
+     serializer_class = AirAverageSerializer
Add pm2.5 avg view api
## Code Before:

from rest_framework import viewsets
from .models import AirCondition, AirAverage
from .serializers import AirAverageSerializer, AirConditionSerializer


class AirConditionViewSets(viewsets.ReadOnlyModelViewSet):
    queryset = AirCondition.objects.all().order_by('-time')[:24]    # 24 hours
    serializer_class = AirConditionSerializer
## Instruction:
Add pm2.5 avg view api
## Code After:

from rest_framework import viewsets
from .models import AirCondition, AirAverage
from .serializers import AirAverageSerializer, AirConditionSerializer


class AirConditionViewSets(viewsets.ReadOnlyModelViewSet):
    queryset = AirCondition.objects.all().order_by('-time')[:24]    # 24 hours
    serializer_class = AirConditionSerializer


class AirAverageViewSets(viewsets.ReadOnlyModelViewSet):
    queryset = AirAverage.objects.all().order_by('-from_time')[:10]     # 5 days
    serializer_class = AirAverageSerializer