Package: djangorestframework-ext
Django REST framework ExtSome extensions of Django REST framework.PaginationDynamicSizePageNumberPaginationSupport settingPAGE_QUERY_PARAM(default ispage) parameter to specify the page size for querying.Return all data when thePAGE_QUERY_PARAM(default islimit) parameter is not specified.Usage:REST_FRAMEWORK = {
    ...
    'DEFAULT_PAGINATION_CLASS': 'djangorestframework_ext.pagination.DynamicSizePageNumberPagination',
    ...
}

REST_FRAMEWORK_EXT = {
    'PAGE_QUERY_PARAM': 'page',  # Default is page (If not set)
    'PAGE_SIZE_QUERY_PARAM': 'limit',
}Request:GET https://api.example.org/accounts/?page=4&limit=100PermissionsIsCurrentUserDetermine whether the object is the current login user.Usage:from djangorestframework_ext.permissions import IsCurrentUserIsSuperuserDetermine whether the request user is superuser.Usage:from djangorestframework_ext.permissions import IsSuperuserSerializersRecursiveSerializerUsage: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
}]ExportModelSerializerUse 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"
}]DynamicFieldsModelSerializerIt's copied fromofficial document.When usingDynamicFieldsModelSerializer, the settings inMetasuch asexcludeandfieldsare ignored. Instead, thefieldsspecified in the parameter that is passed in will take precedence.MixinsMultiFieldLookupMixinFromMultiple lookup_fields for django rest framework.Used for multi field lookup.Usage:views.py:class ExampleViewSet(MultipleFieldLookupMixin, viewsets.ModelViewSet):
    lookup_fields = ['pk', 'field_one', 'field_two']urls.py:urlpatterns = [
    path(r'examples/<str:field_one>/<str:field_two>/', views.ExampleViewSet.as_view({'get': 'retrieve'}))
]ViewSetsExportModelViewSetUseepxortaction andExportPermissionto exporting data.Utilsget_default_query_paramsGet default query params.Viewsexception_handlerSome exception handlers.Usage:REST_FRAMEWORK = {
    ...
    'EXCEPTION_HANDLER': 'djangorestframework_ext.views.exception_handler',
    ...
}ValidatorsActiveValidatorValidate whether the corresponding object is active using the specified key (default isis_active) and value (default isTrue).Usage:from rest_framework import serializers

class MySerializer(serializers.ModelSerializer):
    relation = serializers.PrimaryKeyRelatedField(queryset=Relation.objects.all(), validators=[ActiveValidator()])