from django.contrib import admin
from messenger.models import (
    Message,
    Campaign,
    Receipt,
    CampaignMessage
)

class CampaignMessageInline(admin.TabularInline):
    model = CampaignMessage
    extra = 1

class CampaignAdmin(admin.ModelAdmin):
    inlines = (CampaignMessageInline,)



admin.site.register(Message)
admin.site.register(Campaign, CampaignAdmin)
admin.site.register(Receipt)
from django.contrib import admin
from django.utils.translation import gettext as _
from messenger.models import (
    Message,
    Campaign,
    Receipt,
    CampaignMessage
)

class CampaignMessageInline(admin.TabularInline):
    model = CampaignMessage
    extra = 1

class CampaignAdmin(admin.ModelAdmin):
    inlines = (CampaignMessageInline,)

class EventIdListFilter(admin.SimpleListFilter):

    title = _('Has event Id')

    parameter_name = 'has_event_id'

    def lookups(self, request, model_admin):

        return (
            ('yes', _('Yes')),
            ('no',  _('No')),
        )

    def queryset(self, request, queryset):

        if self.value() == 'yes':
            return queryset.filter(event_id__isnull=False)

        if self.value() == 'no':
            return queryset.filter(event_id__isnull=True)

class ReceiptAdmin(admin.ModelAdmin):
    list_display = (
        'campaign',
        'message',
        'user',
        'event_id',
        'error'
    )
    list_filter = [
        'campaign',
        'message',
        EventIdListFilter,
        'error'
    ]



admin.site.register(Message)
admin.site.register(Campaign, CampaignAdmin)
admin.site.register(Receipt, ReceiptAdmin)
improve messenger admin