From 7a5535bc60569a0a769298abf2f34801ea553ab1 Mon Sep 17 00:00:00 2001
From: Jean-Baptiste <bleme@pm.me>
Date: Mon, 5 Aug 2019 14:04:31 +0200
Subject: [PATCH] update: make django pagination works

---
 README.md                | 10 ++++++++++
 djangoldp/serializers.py |  6 +++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 56d793ee..80c0079b 100644
--- a/README.md
+++ b/README.md
@@ -228,6 +228,16 @@ Only `name` will be serialized
 ## Custom urls
 To add customs urls who can not be add through the `Model` class, it's possible de create a file named `djangoldp_urls.py`. It will be executed like an `urls.py` file
 
+## Pagination
+To enable pagination feature just add this configuration to the server `settings.py` :
+
+```
+REST_FRAMEWORK = {
+    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
+    'PAGE_SIZE': 20
+}
+```
+ 
 ## License
 
 Licence MIT
diff --git a/djangoldp/serializers.py b/djangoldp/serializers.py
index 06b38daa..54bc1b48 100644
--- a/djangoldp/serializers.py
+++ b/djangoldp/serializers.py
@@ -40,10 +40,14 @@ class LDListMixin:
         return [getattr(self, self.child_attr).to_internal_value(item) for item in data]
 
     def to_representation(self, value):
+        try:
+            model = getattr(self, self.child_attr).Meta.model
+        except AttributeError:
+            model = value.model
         return {'@id': self.id,
                 '@type': 'ldp:Container',
                 'ldp:contains': super().to_representation(value),
-                'permissions': Model.get_permissions(value.model, self.context['request'].user, ['view', 'add'])
+                'permissions': Model.get_permissions(model, self.context['request'].user, ['view', 'add'])
                 }
 
     def get_attribute(self, instance):
-- 
GitLab