diff --git a/apps/sspanel/admin.py b/apps/sspanel/admin.py
index 4859990a09..2069768e5b 100644
--- a/apps/sspanel/admin.py
+++ b/apps/sspanel/admin.py
@@ -4,6 +4,9 @@
from django.contrib.auth.models import Group
from django.db.models.query import QuerySet
from django.http.request import HttpRequest
+from django.utils.html import format_html
+
+from apps.sub import UserSubManager
from . import models
@@ -160,10 +163,6 @@ class TicketMessageInline(admin.TabularInline):
extra = 0
raw_id_fields = ["user"]
- def get_queryset(self, request):
- qs = super().get_queryset(request)
- return qs.prefetch_related("user")
-
class TicketAdmin(admin.ModelAdmin):
ALREADY_REPLIED = " | 已回复"
@@ -172,7 +171,7 @@ class TicketAdmin(admin.ModelAdmin):
list_display = ["user_info", "title", "status_info", "updated_at"]
list_filter = ["status"]
search_fields = ["title", "user"]
- readonly_fields = ["updated_at"]
+ readonly_fields = ["user_details"]
list_per_page = 10
@admin.display(description="状态")
@@ -190,13 +189,22 @@ def user_info(self, instance):
user = instance.user
return f"{user.username}-{user.level}-{user.balance}"
+ @admin.display(description="用户详细信息")
+ def user_details(self, instance):
+ user = instance.user
+ base_sub_link = user.sub_link
+ html = '
'
+ html += "Client | Link |
"
+ html += ""
+ for client in UserSubManager.CLIENT_SET:
+ link = f"{base_sub_link}&client={client}"
+ html += format_html(f"{client} | {link} | ")
+ html += "
"
+ html += "
"
+ return format_html(html)
+
def get_queryset(self, request: HttpRequest) -> QuerySet[Any]:
- qs = (
- super()
- .get_queryset(request)
- .prefetch_related("user", "messages")
- .prefetch_related("messages__user")
- )
+ qs = super().get_queryset(request).prefetch_related("messages__user", "user")
return qs
def save_model(
diff --git a/apps/sspanel/models.py b/apps/sspanel/models.py
index 9eb6a12125..2684eed7bc 100644
--- a/apps/sspanel/models.py
+++ b/apps/sspanel/models.py
@@ -1017,7 +1017,11 @@ class Ticket(models.Model):
verbose_name="状态", choices=TICKET_CHOICE, default=1
)
updated_at = models.DateTimeField(
- auto_now=True, db_index=True, help_text="更新时间", verbose_name="更新时间"
+ auto_now=True,
+ db_index=True,
+ help_text="更新时间",
+ verbose_name="更新时间",
+ editable=False,
)
def __str__(self):
@@ -1035,11 +1039,11 @@ class Meta:
@classmethod
def close_stale_tickets(cls):
dt = get_current_datetime().subtract(days=3)
- tickets = cls.objects.filter(updated_at__lt=dt, status=1)
+ tickets = list(cls.objects.filter(updated_at__lt=dt, status=1))
for t in tickets:
t.title += " |3 天无更新自动关闭"
t.status = -1
- t.save()
+ cls.objects.bulk_update(tickets, ["title", "status"])
def add_message(self, user, message):
return TicketMessage.create_message(user, self, message)