from django.contrib import admin

from coin.vpn.models import VPNSubscription

# TODO: allow to regenerate IP endpoints (checkbox?)
class VPNAdmin(admin.ModelAdmin):
    list_display = ('administrative_subscription', 'activated', 'login',
                    'ipv4_endpoint', 'ipv6_endpoint', 'comment')
    list_filter = ('activated',)
    search_fields = ('login', 'comment',
                     # TODO: searching on member directly doesn't work
                     'administrative_subscription__member__first_name',
                     'administrative_subscription__member__last_name',
                     'administrative_subscription__member__email')


    def get_readonly_fields(self, request, obj=None):
        if obj:
            return ['login',]
        else:
            return []

admin.site.register(VPNSubscription, VPNAdmin)
