2026-07-02 09:07:15 +08:00
|
|
|
from django.contrib import admin
|
|
|
|
|
|
2026-07-03 09:07:21 +08:00
|
|
|
from .models import CallRecord, ExchangeRate, PointsLedger, PricingRule, RechargeOrder
|
2026-07-02 15:06:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ReadOnlyLedgerAdmin(admin.ModelAdmin):
|
|
|
|
|
def get_readonly_fields(self, request, obj=None):
|
|
|
|
|
return tuple(field.name for field in self.model._meta.fields)
|
|
|
|
|
|
|
|
|
|
def has_add_permission(self, request):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def has_change_permission(self, request, obj=None):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def has_delete_permission(self, request, obj=None):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(PointsLedger)
|
|
|
|
|
class PointsLedgerAdmin(ReadOnlyLedgerAdmin):
|
|
|
|
|
list_display = (
|
|
|
|
|
"created_at",
|
|
|
|
|
"user",
|
|
|
|
|
"change_type",
|
|
|
|
|
"points_delta",
|
|
|
|
|
"balance_after",
|
|
|
|
|
"ref_order_id",
|
|
|
|
|
"ref_call",
|
|
|
|
|
)
|
|
|
|
|
list_filter = ("change_type", "created_at")
|
2026-07-03 16:36:06 +08:00
|
|
|
search_fields = ("user__username", "user__email", "=ref_order_id", "reason")
|
2026-07-02 15:06:00 +08:00
|
|
|
ordering = ("-created_at", "-id")
|
2026-07-03 16:36:06 +08:00
|
|
|
date_hierarchy = "created_at"
|
|
|
|
|
list_select_related = ("user", "ref_call")
|
2026-07-02 15:06:00 +08:00
|
|
|
|
|
|
|
|
|
2026-07-02 15:28:19 +08:00
|
|
|
@admin.register(PricingRule)
|
|
|
|
|
class PricingRuleAdmin(admin.ModelAdmin):
|
|
|
|
|
list_display = (
|
|
|
|
|
"operation_type",
|
|
|
|
|
"alias",
|
|
|
|
|
"resolution_display",
|
|
|
|
|
"points_cost",
|
|
|
|
|
"is_active",
|
|
|
|
|
"updated_at",
|
|
|
|
|
)
|
|
|
|
|
list_filter = ("operation_type", "is_active")
|
|
|
|
|
search_fields = ("alias", "resolution")
|
|
|
|
|
ordering = ("operation_type", "alias", "resolution")
|
|
|
|
|
readonly_fields = ("created_at", "updated_at")
|
2026-07-03 16:36:06 +08:00
|
|
|
list_editable = ("points_cost", "is_active")
|
2026-07-02 15:28:19 +08:00
|
|
|
|
|
|
|
|
@admin.display(description="resolution")
|
|
|
|
|
def resolution_display(self, obj):
|
|
|
|
|
return obj.resolution or "*"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(ExchangeRate)
|
|
|
|
|
class ExchangeRateAdmin(admin.ModelAdmin):
|
|
|
|
|
list_display = (
|
|
|
|
|
"currency",
|
|
|
|
|
"points_per_unit",
|
|
|
|
|
"is_active",
|
|
|
|
|
"effective_from",
|
|
|
|
|
"updated_at",
|
|
|
|
|
)
|
|
|
|
|
list_filter = ("currency", "is_active")
|
|
|
|
|
search_fields = ("currency", "note")
|
|
|
|
|
ordering = ("-effective_from", "-id")
|
|
|
|
|
readonly_fields = ("created_at", "updated_at")
|
2026-07-03 16:36:06 +08:00
|
|
|
list_editable = ("is_active",)
|
|
|
|
|
date_hierarchy = "effective_from"
|
2026-07-02 15:28:19 +08:00
|
|
|
|
|
|
|
|
|
2026-07-03 09:07:21 +08:00
|
|
|
@admin.register(RechargeOrder)
|
|
|
|
|
class RechargeOrderAdmin(ReadOnlyLedgerAdmin):
|
|
|
|
|
list_display = (
|
|
|
|
|
"created_at",
|
|
|
|
|
"order_no",
|
|
|
|
|
"user",
|
|
|
|
|
"pay_method",
|
|
|
|
|
"status",
|
|
|
|
|
"amount_money",
|
|
|
|
|
"currency",
|
|
|
|
|
"points_granted",
|
|
|
|
|
"payment_txn_no",
|
|
|
|
|
"paid_at",
|
|
|
|
|
)
|
|
|
|
|
list_filter = ("pay_method", "status", "currency", "created_at")
|
|
|
|
|
search_fields = (
|
|
|
|
|
"order_no",
|
|
|
|
|
"user__username",
|
|
|
|
|
"user__email",
|
|
|
|
|
"payment_txn_no",
|
|
|
|
|
)
|
|
|
|
|
ordering = ("-created_at", "-id")
|
2026-07-03 16:36:06 +08:00
|
|
|
date_hierarchy = "created_at"
|
|
|
|
|
list_select_related = ("user",)
|
2026-07-03 09:07:21 +08:00
|
|
|
|
|
|
|
|
|
2026-07-02 15:06:00 +08:00
|
|
|
@admin.register(CallRecord)
|
|
|
|
|
class CallRecordAdmin(ReadOnlyLedgerAdmin):
|
|
|
|
|
list_display = (
|
|
|
|
|
"created_at",
|
|
|
|
|
"user",
|
|
|
|
|
"api_key",
|
|
|
|
|
"operation_type",
|
|
|
|
|
"alias",
|
|
|
|
|
"model_used",
|
|
|
|
|
"points_cost",
|
|
|
|
|
"status",
|
|
|
|
|
"upstream_latency_ms",
|
|
|
|
|
)
|
|
|
|
|
list_filter = ("operation_type", "status", "created_at")
|
|
|
|
|
search_fields = (
|
|
|
|
|
"user__username",
|
|
|
|
|
"user__email",
|
|
|
|
|
"api_key__key_prefix",
|
|
|
|
|
"alias",
|
|
|
|
|
"model_used",
|
2026-07-03 16:36:06 +08:00
|
|
|
"prompt",
|
2026-07-02 15:06:00 +08:00
|
|
|
"error_message",
|
|
|
|
|
"result_ref",
|
|
|
|
|
"result_summary",
|
|
|
|
|
)
|
|
|
|
|
ordering = ("-created_at", "-id")
|
2026-07-03 16:36:06 +08:00
|
|
|
date_hierarchy = "created_at"
|
|
|
|
|
list_select_related = ("user", "api_key")
|