add sort
This commit is contained in:
@@ -3,7 +3,7 @@ import re
|
|||||||
import xlsxwriter
|
import xlsxwriter
|
||||||
|
|
||||||
from django.db import transaction, IntegrityError
|
from django.db import transaction, IntegrityError
|
||||||
from django.db.models import Q
|
from django.db.models import Q, F
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.contrib.auth.hashers import make_password
|
from django.contrib.auth.hashers import make_password
|
||||||
from django.utils.crypto import get_random_string
|
from django.utils.crypto import get_random_string
|
||||||
@@ -154,6 +154,18 @@ class UserAdminAPI(APIView):
|
|||||||
return self.error("User does not exist")
|
return self.error("User does not exist")
|
||||||
return self.success(UserAdminSerializer(user).data)
|
return self.success(UserAdminSerializer(user).data)
|
||||||
|
|
||||||
|
# 获取排序参数
|
||||||
|
order_by = request.GET.get("order_by", "")
|
||||||
|
|
||||||
|
# 根据排序参数设置排序规则
|
||||||
|
if order_by == "-last_login":
|
||||||
|
# 最近登录,将 None 值放在最后
|
||||||
|
user = User.objects.all().order_by(F("last_login").desc(nulls_last=True))
|
||||||
|
elif order_by == "last_login":
|
||||||
|
# 最早登录,将 None 值放在最后
|
||||||
|
user = User.objects.all().order_by(F("last_login").asc(nulls_last=True))
|
||||||
|
else:
|
||||||
|
# 默认按创建时间倒序
|
||||||
user = User.objects.all().order_by("-create_time")
|
user = User.objects.all().order_by("-create_time")
|
||||||
|
|
||||||
type = request.GET.get("type", "")
|
type = request.GET.get("type", "")
|
||||||
|
|||||||
Reference in New Issue
Block a user