我目前有一个 API 视图设置如下:
class WeatherObservationSerializer(serializers.ModelSerializer):
dew_point = serializers.Field(source='dew_point')
wind_gust = serializers.Field(source='get_wind_gust')
class Meta:
model = WeatherObservation
fields = ('id', 'station', 'temperature', 'pressure', 'humidity',
'wind_direction', 'wind_speed', 'rainfall', 'date',
'dew_point', 'wind_gust')
class WeatherObservationList(generics.ListCreateAPIView):
model = WeatherObservation
serializer_class = WeatherObservationSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
def get_queryset(self):
queryset = WeatherObservation.objects.all()
min_date = self.request.QUERY_PARAMS.get('min_date', None)
station = self.request.QUERY_PARAMS.get('station', None)
if min_date is not None:
queryset = queryset.filter(date__gte=min_date)
if station is not None:
queryset = queryset.filter(station=station)
return queryset
我的settings.py
包含:REST_FRAMEWORK = { 'PAGINATE_BY': 50, 'PAGINATE_BY_PARAM': 'page' }
当我像这样向 API 发出请求时: /api/weather/observations/?station=2&page=2&min_date=2013-3-14 我只得到两个结果。如果是第 3 页、第 3 个结果等。有什么我做错了导致这个问题吗?
干杯。