From b05dbda8f9a5d3fc7dd2e8cd1fe39109e145b640 Mon Sep 17 00:00:00 2001 From: retroinspect Date: Tue, 23 Jan 2024 12:28:48 +0000 Subject: [PATCH] fix(article): use id instead of created_at for order_by --- apps/core/migrations/0057_alter_article_name_type_and_more.py | 3 +-- apps/core/models/article.py | 4 ++-- apps/core/views/viewsets/article.py | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/core/migrations/0057_alter_article_name_type_and_more.py b/apps/core/migrations/0057_alter_article_name_type_and_more.py index d23bfcbf..e3c7ed88 100644 --- a/apps/core/migrations/0057_alter_article_name_type_and_more.py +++ b/apps/core/migrations/0057_alter_article_name_type_and_more.py @@ -23,8 +23,7 @@ class Migration(migrations.Migration): migrations.AddIndex( model_name="article", index=models.Index( - fields=["created_at", "parent_board_id"], - name="created_at_parent_board_id_idx", + fields=["id", "parent_board_id"], name="id_parent_board_id_idx" ), ), ] diff --git a/apps/core/models/article.py b/apps/core/models/article.py index 4525bc4e..dd9eee68 100644 --- a/apps/core/models/article.py +++ b/apps/core/models/article.py @@ -160,8 +160,8 @@ class Meta(MetaDataModel.Meta): indexes = [ models.Index( - fields=["created_at", "parent_board_id"], - name="created_at_parent_board_id_idx", + fields=["id", "parent_board_id"], + name="id_parent_board_id_idx", ) ] diff --git a/apps/core/views/viewsets/article.py b/apps/core/views/viewsets/article.py index ccacb708..68b5b721 100644 --- a/apps/core/views/viewsets/article.py +++ b/apps/core/views/viewsets/article.py @@ -45,7 +45,7 @@ class ArticleViewSet(viewsets.ModelViewSet, ActionAPIViewSet): queryset = Article.objects.all() filterset_class = ArticleFilter - ordering_fields = ["created_at", "positive_vote_count"] + ordering_fields = ["id", "positive_vote_count"] serializer_class = ArticleSerializer action_serializer_class = {