from django.contrib import admin

from apps.ads.models import AdvertisementSpace, Advertisement, AdDeliveryRule


class AdDeliveryRuleInline(admin.StackedInline):
    model = AdDeliveryRule
    extra = 1
    # 定义只读字段
    readonly_fields = ('regions', 'devices')


@admin.register(Advertisement)
class AdvertisementAdmin(admin.ModelAdmin):
    list_display = ('title', 'space', 'is_valid', 'audit_status')
    list_filter = ('space__space_type', 'audit_status')
    inlines = [AdDeliveryRuleInline]
    readonly_fields = ('click_count', 'show_count')


@admin.register(AdvertisementSpace)
class AdvertisementSpaceAdmin(admin.ModelAdmin):
    list_display = ('name', 'identifier', 'get_space_type_display', 'position')
    list_editable = ('position', )
