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',
        'user'
    ]



admin.site.register(Message)
admin.site.register(Campaign, CampaignAdmin)
admin.site.register(Receipt, ReceiptAdmin)
@@ -974,16 +974,36 @@
  'error'
+,%0A        'created',
 %0A    )%0A 
@@ -1118,16 +1118,36 @@
   'user'
+,%0A        'created',
 %0A    %5D%0A%0A

improve messenger admin