Extensions of Django Rest framework
Project description
Django REST framework Ext
Some extensions of Django REST framework.
DynamicSizePageNumberPagination
Support using limit
parameter to specify the page size for querying.
Return all data when the page
parameter is not specified.
Usage:
REST_FRAMEWORK = {
...
'DEFAULT_PAGINATION_CLASS': 'djangorestframework_ext.pagination.DynamicSizePageNumberPagination',
...
}
Request:
GET https://api.example.org/accounts/?page=4&limit=100
DjangoModelPermissions
Add view
permission control.
Usage:
from djangorestframework_ext.permissions import DjangoModelPermissions
IsCurrentUser
Determine whether it is the current login user.
Usage:
from djangorestframework_ext.permissions import IsCurrentUser
RecursiveSerializer
Usage:
from rest_framework import serializers
from djangorestframework_ext.serializers import RecursiveSerializer
from django.db import models
class Department(models.Model):
name = models.CharField('Name', max_length=100)
parent = models.ForeignKey('self', related_name='children', verbose_name='Parent')
class DepartmentTreeListSerializer(serializers.ModelSerializer):
children = RecursiveSerializer(many=True)
class Meta:
model = Department
fields = '__all__'
Response:
[{
"id": 1,
"children": [{
"id": 2,
"children": [{
"id": 3,
"children": [{
"id": 4,
"children": [],
"name": "aaa",
"parent": 3
}],
"name": "ddd",
"parent": 2
}, {
"id": 5,
"children": [{
"id": 6,
"children": [],
"name": "eee",
"parent": 7
}],
"name": "xxx",
"parent": 2
}],
"name": "yyy",
"parent": 1
}],
"name": "zzz",
"parent": null
}]
ExportModelSerializer
Use verbose name or label replace field name.
Usage:
from djangorestframework_ext.serializers import ExportModelSerializer
from django.db import models
class Department(models.Model):
name = models.CharField('Name', max_length=100)
creator = models.ForeignKey(User, null=False, verbose_name='Creator')
class DepartmentExportSerializer(ExportModelSerializer):
creator = serializers.StringRelatedField(label='Creator', read_only=True)
class Meta:
model = Department
fields = ['name', 'creator']
Response:
[{
"Name": "aaa",
"Creator": "John"
}]
DynamicFieldsModelSerializer
It's copied from official document.
DEFAULT_QUERY_PARAMS
Default query params: page_query_param
, page_size_query_param
and ORDERING_PARAM
.
exception_handler
Some exception handlers.
Usage:
REST_FRAMEWORK = {
...
'EXCEPTION_HANDLER': 'djangorestframework_ext.views.exception_handler',
...
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for djangorestframework-ext-0.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c44e45608e932396348e128341a428913666c4ad8654c4ebaa512beeca5dcb9 |
|
MD5 | 65f735fae2c048d9fba1abf64711cb05 |
|
BLAKE2b-256 | 62e554b14cd1a27fa09586d44b3fa9e8597602c6fb0f09c16defdd137a8dc52b |
Close
Hashes for djangorestframework_ext-0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb30bd0f54348b702f99bb870845cd2d02c362d5430c5f818ac0795f400055dd |
|
MD5 | 63b8c9497ce0727d566d5bb40254bfd8 |
|
BLAKE2b-256 | 29273d89bc25ba831084af7765fb2caeb63ef8fde0b24118622a65e878ea3fbd |