“缺少计数”属性在“模型”视图中

时间:2016-10-13 08:50:37

标签: django django-rest-framework

我正在使用Modelviewsets,一切正常,预计响应中没有count参数。我怀疑可能是分页不起作用,但我在DRF设置中定义了分页

设置:

'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGINATE_BY': 100,                 # Default to 10
'PAGINATE_BY_PARAM': 'page_size',  # Allow client to override, using `?page_size=xxx`.
'MAX_PAGINATE_BY': 10             # Maximum limit allowed when using `?page_size=xxx`.

观点:

class VenueViewSet(viewsets.ModelViewSet):
    """
    Manage CRUD on venues here
    """
    queryset = Venue.objects.all()
    serializer_class = serializers.VenueSerializer
    filter_backends = (ModifiedFilterBackend,)
    paginate_by = settings.VENUES_PAGINATION

回复:

[
  {
    "id": 54,
    "name": "v1",
    "description": "dfqw",
    "address": {
      "city": {
        "name": "abc",
        "state": {
          "name": "PO",
          "code": "MK"
        },
        "country": {
          "name": "XYZ",
          "code": "XY"
        },
        "id": 22
      },
      "address_line_1": "abcd",
      "address_line_2": "qwert",
      "zip_code": 123654,
      "place_id": null
    },
    "is_deleted": false,
    "parent": null
  }
]

1 个答案:

答案 0 :(得分:1)

我认为您错过了PAGE_SIZE设置。请参考this

REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 100
}