♻️(backend) api resources list ordering

Give the possibility to order the resources
list by creation date (documents / templates).
By default the list is ordered by
creation date descending.
This commit is contained in:
Anthony LC
2024-04-16 09:56:18 +02:00
committed by Anthony LC
parent db9c9ecfe3
commit f9705c6ce9
3 changed files with 117 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ from django.http import FileResponse
from rest_framework import (
decorators,
exceptions,
filters,
mixins,
pagination,
status,
@@ -138,6 +139,10 @@ class UserViewSet(
class ResourceViewsetMixin:
"""Mixin with methods common to all resource viewsets that are managed with accesses."""
filter_backends = [filters.OrderingFilter]
ordering_fields = ["created_at"]
ordering = ["-created_at"]
def get_queryset(self):
"""Custom queryset to get user related resources."""
queryset = super().get_queryset()