41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
from django.contrib import admin
|
|
from .models import Coupon
|
|
|
|
|
|
class CouponAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
"id",
|
|
"title",
|
|
"coupon_id",
|
|
"coupon_code",
|
|
"discount_amount",
|
|
"discount_percentage",
|
|
"valid_from",
|
|
"valid_to",
|
|
"max_redeems",
|
|
"no_of_redeems",
|
|
"is_active",
|
|
)
|
|
search_fields = ("title", "coupon_code")
|
|
list_filter = ("valid_from", "valid_to", "max_redeems")
|
|
readonly_fields = ("no_of_redeems",)
|
|
|
|
fieldsets = (
|
|
(
|
|
None,
|
|
{"fields": ("title", "coupon_code", "coupon_id", "description", "image")},
|
|
),
|
|
(
|
|
"Discount Information",
|
|
{"fields": ("discount_amount", "discount_percentage")},
|
|
),
|
|
("Validity", {"fields": ("valid_from", "valid_to")}),
|
|
("Redemption", {"fields": ("max_redeems", "no_of_redeems")}),
|
|
)
|
|
|
|
def is_active(self, obj):
|
|
return obj.is_valid()
|
|
|
|
|
|
admin.site.register(Coupon, CouponAdmin)
|