40356-vm/core/admin.py
2026-06-30 00:27:36 +00:00

41 lines
1.8 KiB
Python

from django.contrib import admin
from django.utils import timezone
from .models import PaymentConfirmation, Product, ProductCategory
@admin.register(ProductCategory)
class ProductCategoryAdmin(admin.ModelAdmin):
list_display = ("name", "slug", "is_active", "sort_order")
list_editable = ("is_active", "sort_order")
prepopulated_fields = {"slug": ("name",)}
search_fields = ("name", "description")
@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
list_display = ("name", "category", "price_from", "delivery_time", "is_featured", "is_active")
list_filter = ("category", "is_featured", "is_active")
list_editable = ("price_from", "is_featured", "is_active")
prepopulated_fields = {"slug": ("name",)}
search_fields = ("name", "short_description", "description")
@admin.register(PaymentConfirmation)
class PaymentConfirmationAdmin(admin.ModelAdmin):
list_display = ("customer_name", "product", "method", "amount", "reference", "status", "created_at")
list_filter = ("status", "method", "created_at")
search_fields = ("customer_name", "customer_phone", "customer_email", "reference")
readonly_fields = ("created_at",)
actions = ("approve_payments", "reject_payments")
@admin.action(description="Aprobar pagos seleccionados")
def approve_payments(self, request, queryset):
updated = queryset.update(status=PaymentConfirmation.STATUS_APPROVED, reviewed_at=timezone.now())
self.message_user(request, f"{updated} confirmación(es) aprobada(s).")
@admin.action(description="Rechazar pagos seleccionados")
def reject_payments(self, request, queryset):
updated = queryset.update(status=PaymentConfirmation.STATUS_REJECTED, reviewed_at=timezone.now())
self.message_user(request, f"{updated} confirmación(es) rechazada(s).")