diff --git a/README.md b/README.md index 56d793eefbb669715c4669c353ba26840c1058d6..80c0079bb73aceea9087dab7703d6b9352f81f82 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 06b38daad1f3c21a5b72e312f322631f2ff9ae2a..54bc1b48d733234fb0b73b111a445dc1e18340d9 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):