Django/Wagtail Rest Framework API Ordering/Pagination

Я использую трясогузку. Я сериализовал свои API. Я хочу упорядочить их по -first_published_at, когда кто-то нажмет на мой API url api/v2/pages он увидит упорядоченный API без фильтрации по URL. вот мой api.py код:

class ProdPagesAPIViewSet(BaseAPIViewSet):
    renderer_classes = [JSONRenderer]
    filter_backends = [FieldsFilter,
        ChildOfFilter,
        AncestorOfFilter,
        DescendantOfFilter,
        OrderingFilter,
        TranslationOfFilter,
        LocaleFilter,
        SearchFilter,]
    meta_fields = ["type","seo_title","search_description","first_published_at"]
    body_fields = ["id","type","seo_title","search_description","first_published_at","title"]
    listing_default_fields = ["type","seo_title","search_description","first_published_at","id","title","alternative_title","news_slug","blog_image","video_thumbnail","categories","blog_authors","excerpt","content","content2","tags",]
    nested_default_fields = []
    ordered_queryset= [] 
    name = "pages"
    model = AddStory

api_router.register_endpoint("pages", ProdPagesAPIViewSet)

Я пробовал ordered_queryset= [AddStory.objects.order_by('-first_published_at')]

Но он не упорядочен по самым новым опубликованным рассказам. Как я должен сделать запрос?

Вот мой ответ API

{
  "meta": {
    "total_count": 6
  },
  "items": [
    {
      "id": 4,
      "meta": {
        "type": "blog.AddStory",
        "seo_title": "",
        "search_description": "",
        "first_published_at": "2022-08-30T11:05:11.341355Z"
      },
    {
      "id": 6,
      "meta": {
        "type": "blog.AddStory",
        "seo_title": "",
        "search_description": "",
        "first_published_at": "2022-08-30T11:13:47.114889Z"
      },
{
  "id": 7,
  "meta": {
    "type": "blog.AddStory",
    "seo_title": "",
    "search_description": "",
    "first_published_at": "2022-08-31T11:13:47.114889Z"
  },
<
class ProdPagesAPIViewSet(BaseAPIViewSet):
    renderer_classes = [JSONRenderer]
    filter_backends = [FieldsFilter,
        ChildOfFilter,
        AncestorOfFilter,
        DescendantOfFilter,
        OrderingFilter,
        TranslationOfFilter,
        LocaleFilter,
        SearchFilter,]
    meta_fields = ["type","seo_title","search_description","first_published_at"]
    body_fields = ["id","type","seo_title","search_description","first_published_at","title"]
    listing_default_fields = ["type","seo_title","search_description","first_published_at","id","title","alternative_title","news_slug","blog_image","video_thumbnail","categories","blog_authors","excerpt","content","content2","tags",]
    nested_default_fields = []
    def get_queryset(self):
        return self.model.objects.all().order_by("-first_published_at")
    name = "pages"
    model = AddStory

api_router.register_endpoint("pages", ProdPagesAPIViewSet)
Вернуться на верх