Skip to content
Snippets Groups Projects
Commit a868600e authored by dominip89's avatar dominip89
Browse files

Merge branch 'react-rest-connection' into 'master'

Add pagination to Django REST API

See merge request swp-unisport/team-warumkeinrust/unisport-o-mat!42
parents a4f67966 00da25c7
No related branches found
No related tags found
No related merge requests found
"""
Adds the ability paginate content provided via REST API.
Can either be given as an argument in a model
or be given globally via settings.py.
"""
from rest_framework.pagination import PageNumberPagination
class PageNumberWithPageSizePagination(PageNumberPagination):
"""
This pagination style accepts a single number page number
in the request query parameters.
SOURCE: https://github.com/bmihelac/ra-data-django-rest-framework
"""
page_size_query_param = "page_size"
......@@ -32,6 +32,8 @@ ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
"corsheaders", # CORS Headers should be as high as possible.
"rest_framework",
# "quiz.apps.QuizConfig",
"django.contrib.admin",
"django.contrib.auth",
......@@ -39,12 +41,11 @@ INSTALLED_APPS = [
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"rest_framework",
"corsheaders",
"quiz",
]
MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware", # CORS Middleware should be as high as possible.
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
......@@ -52,9 +53,14 @@ MIDDLEWARE = [
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"corsheaders.middleware.CorsMiddleware",
]
# SOURCE: https://github.com/bmihelac/ra-data-django-rest-framework
REST_FRAMEWORK = {
"DEFAULT_PAGINATION_CLASS": "quiz.pagination.PageNumberWithPageSizePagination",
"PAGE_SIZE": 10,
}
ROOT_URLCONF = "unisportomat.urls"
TEMPLATES = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment