0
我有進行分頁記錄(每頁10條)如下一種觀點:如何在Django REST中處理當前頁面的記錄?
class Foo(models.Model):
bar = models.BooleanField(db_index=True)
user = models.ForeignKey(User, db_index=True, editable=False)
baz = models.CharField(max_length=120)
created = models.DateTimeField(db_index=True, auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
class UserSerializer(ModelSerializer):
class Meta:
model = User
fields = ('id', 'username')
class FooSerializer(ModelSerializer):
user = UserSerializer()
class Meta:
model = Foo
class FooPagination(PageNumberPagination):
page_size = 10
class FooView(ListAPIView):
serializer_class = FooSerializer
pagination_class = FooPagination
def get_queryset(self):
user = self.request.user
'''
Do something here (or when page is requested) with each record on
the current page.
'''
return Foo.objects.filter(bar=true, user=user).order_by('created')
我如何處理美孚僅記錄在當前頁面上?
我用:「def foo_decorator(obj,queryset,request)」和ListAPIView而不是GenericAPIView。 – tyebillion
裝飾工作正常,但我沒有收到JSON結果字段中的任何數據。 – tyebillion
...即使計數不爲零。 – tyebillion