Reputation: 325
MyPostList.py
class PostList(viewsets.ModelViewSet):
queryset = Postinfo.objects.all().order_by('-postuid')[:10]
serializer_class = PostListSerializer
PostListSerializer.py
class PostListSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Postinfo
fields = ("content",
"useruid")
models.py
class Postinfo(models.Model):
postuid = models.BigAutoField(db_column='WorryUID', primary_key=True)
useruid = models.BigIntegerField(db_column='UserUID')
content = models.TextField(db_column='Content')
registerdate = models.DateTimeField(
db_column='RegisterDate', default=datetime.datetime.today().strftime("%Y-%m-%dT%H:%M:%S"))
class Meta:
managed = False
db_table = 'postinfo'
i want response pagenumber if i request PostList i want response postlist and PageNo like this
queryset = Postinfo.objects.all().order_by('-postuid')[:10]
{"PostList":queryset,
"PageNo":1}
and i send pageNo = 2
queryset = Postinfo.objects.all().order_by('-postuid')[10:20]
{"PostList":queryset,
"PageNo":2}
i have two problem
first request(GET) succes PostList but can't add PageNo
if i send PageNo it is not request(GET) this is POST so call create() i want return PostList and PageNo , want not mysql insert
Upvotes: 1
Views: 283
Reputation: 354
Django Rest Framework has builtin pagination system. You don't have to manually create pagination. You can just pagination_class
to your views to add pagination. Please read the documentation for more details.
http://www.django-rest-framework.org/api-guide/pagination/
Upvotes: 1