Skip to content
Snippets Groups Projects
Commit 7a5535bc authored by Jean-Baptiste's avatar Jean-Baptiste
Browse files

update: make django pagination works

parent cd9a45ee
No related branches found
No related tags found
1 merge request!83Resolve "Server side paging"
Pipeline #1081 passed
...@@ -228,6 +228,16 @@ Only `name` will be serialized ...@@ -228,6 +228,16 @@ Only `name` will be serialized
## Custom urls ## 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 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 ## License
Licence MIT Licence MIT
...@@ -40,10 +40,14 @@ class LDListMixin: ...@@ -40,10 +40,14 @@ class LDListMixin:
return [getattr(self, self.child_attr).to_internal_value(item) for item in data] return [getattr(self, self.child_attr).to_internal_value(item) for item in data]
def to_representation(self, value): def to_representation(self, value):
try:
model = getattr(self, self.child_attr).Meta.model
except AttributeError:
model = value.model
return {'@id': self.id, return {'@id': self.id,
'@type': 'ldp:Container', '@type': 'ldp:Container',
'ldp:contains': super().to_representation(value), '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): def get_attribute(self, instance):
......
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