from django.contrib import admin
from coin.offers.models import Offer, Service, OfferSubscription
from coin.offers.offersubscription_filter import\
            OfferSubscriptionTerminationFilter,\
            OfferSubscriptionCommitmentFilter
import autocomplete_light

class ServiceAdmin(admin.ModelAdmin):
    search_fields = ['name']


class OfferAdmin(admin.ModelAdmin):
    list_display = ('service', 'name', 'billing_period', 'period_fees',
                    'initial_fees')
    list_display_links = ('name',)
    search_fields = ['name']


class OfferSubscriptionAdmin(admin.ModelAdmin):
    list_display = ('member', 'offer', 'subscription_date', 'commitment',
                    'resign_date')
    list_display_links = ('member','offer')
    list_filter = ( OfferSubscriptionTerminationFilter,
                    OfferSubscriptionCommitmentFilter,
                    'member', 'offer')
    search_fields = ['member__first_name', 'member__last_name', 'member__email']
    
    fields = (
                'member',
                'offer',
                'subscription_date',
                'commitment',
                'resign_date'
             )
    form = autocomplete_light.modelform_factory(OfferSubscription)

admin.site.register(Service, ServiceAdmin)
admin.site.register(Offer, OfferAdmin)
admin.site.register(OfferSubscription, OfferSubscriptionAdmin)
