Skip to content

Commit

Permalink
feat: Add "ALREADY_REPLIED" suffix to ticket title if not already pre…
Browse files Browse the repository at this point in the history
…sent
  • Loading branch information
Ehco1996 committed Jan 15, 2024
1 parent 474a313 commit 2f84211
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions apps/sspanel/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ def get_queryset(self, request):


class TicketAdmin(admin.ModelAdmin):
ALREADY_REPLIED = " | 已回复"

inlines = [TicketMessageInline]
list_display = ["user", "title", "status_info", "updated_at"]
list_filter = ["status"]
Expand All @@ -141,17 +143,28 @@ class TicketAdmin(admin.ModelAdmin):

@admin.display(description="状态")
def status_info(self, instance):
return instance.status_with_message_count
res = instance.status_with_message_count
last_reply = instance.messages.last()
if not last_reply.user.is_staff:
res += " | 未读"
return res

def get_queryset(self, request: HttpRequest) -> QuerySet[Any]:
qs = (
super()
.get_queryset(request)
.prefetch_related("user")
.prefetch_related("user", "messages")
.prefetch_related("messages__user")
)
return qs

def save_model(
self, request: Any, obj: models.Ticket, form: Any, change: Any
) -> None:
if self.ALREADY_REPLIED not in obj.title:
obj.title += self.ALREADY_REPLIED
return super().save_model(request, obj, form, change)


# Register your models here.
admin.site.register(models.User, UserAdmin)
Expand Down

0 comments on commit 2f84211

Please sign in to comment.