Skip to content

Commit 69ba177

Browse files
committed
refactor: enhance ordering logic for application and system API key queries
1 parent 11d2991 commit 69ba177

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

apps/application/serializers/application_api_key.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ def page(self, current_page: int, page_size: int, with_valid=True):
6565
self.is_valid(raise_exception=True)
6666
application_id = self.data.get("application_id")
6767
query_set = QuerySet(ApplicationApiKey).filter(application_id=application_id)
68-
if self.data.get('order_by'):
69-
query_set = query_set.order_by(self.data.get('order_by'))
68+
order_by = '-create_time' if self.data.get('order_by') is None or self.data.get(
69+
'order_by') == '' else self.data.get('order_by')
70+
query_set = query_set.order_by(order_by)
7071
return page_search(current_page, page_size,
7172
query_set,
7273
post_records_handler=lambda u: ApplicationKeySerializerModel(u).data)

0 commit comments

Comments
 (0)