Files
MathApp/support/admin.py
2026-08-11 16:43:12 +03:30

53 lines
1.9 KiB
Python
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from django.contrib import admin
from .models import BugReport, Ticket, TicketMessage
class TicketMessageInline(admin.TabularInline):
model = TicketMessage
extra = 0
readonly_fields = ('created_at',)
@admin.register(BugReport)
class BugReportAdmin(admin.ModelAdmin):
list_display = ('id', 'user_id', 'title', 'status', 'linked_ticket_id', 'created_at')
list_filter = ('status',)
search_fields = ('title',)
@admin.register(Ticket)
class TicketAdmin(admin.ModelAdmin):
list_display = ('id', 'user_id', 'subject', 'category', 'status', 'priority', 'created_at')
list_filter = ('status', 'priority', 'category')
search_fields = ('subject',)
inlines = [TicketMessageInline]
@admin.register(TicketMessage)
class TicketMessageAdmin(admin.ModelAdmin):
list_display = ('id', 'ticket', 'sender', 'created_at')
list_filter = ('sender',)
def save_model(self, request, obj, form, change):
"""
طبق سند معماری، ارتباط Support→Notifications فقط از طریق رویداد
TicketReplied‌ه، نه رفرنس مدل. چون پاسخ پشتیبانی (sender='support')
از پنل ادمین ثبت می‌شه، رویداد دقیقاً همین‌جا ساطع می‌شه — همون
الگوی notify() که در payment/views.py (PaymentWebhookView) هنگام
پرداخت موفق (status=paid) صدا زده می‌شه.
"""
is_new = obj.pk is None
super().save_model(request, obj, form, change)
if is_new and obj.sender == 'support':
from notifications.services import notify
notify(
user_id=obj.ticket.user_id,
type='ticket_replied',
title='پاسخ جدید برای تیکت شما',
body=obj.text[:200],
related_id=obj.ticket_id,
)