from django.contrib import admin

from salt_observer.models import (
    Minion, Network, NetworkInterface, Domain
)


class NetworkInterfaceInline(admin.TabularInline):
    model = NetworkInterface
    extra = 0
    readonly_fields = ('network', 'minion', 'mac_address', 'name')

    def has_add_permission(self, request):
        return False

    def has_delete_permission(self, request, obj=None):
        return False


class MinionAdmin(admin.ModelAdmin):
    inlines = [NetworkInterfaceInline]
    readonly_fields = ('fqdn', 'data', 'last_updated')
    exclude = ('_data',)
admin.site.register(Minion, MinionAdmin)


class NetworkAdmin(admin.ModelAdmin):
    inlines = [NetworkInterfaceInline]
    readonly_fields = ('ipv4', 'mask', 'last_updated')
    exclude = ('md_content',)
admin.site.register(Network, NetworkAdmin)


class DomainAdmin(admin.ModelAdmin):
    list_display = ('fqdn', 'minion_count', 'valid', 'public', 'can_speak_https')
    filter_horizontal = ('minion',)
    readonly_fields = ('ssl_lab_status',)
    exclude = ('_ssl_lab_status', 'md_content')
admin.site.register(Domain, DomainAdmin)

@@ -249,16 +249,30 @@
 minion',
+ 'ip_address',
  'mac_ad
@@ -287,16 +287,16 @@
 'name')%0A
-
 %0A    def
@@ -586,16 +586,64 @@
 '_data',
+ 'md_content', 'md_last_edited', 'md_last_autor'
 )%0Aadmin.
@@ -839,16 +839,50 @@
 ontent',
+ 'md_last_edited', 'md_last_autor'
 )%0Aadmin.
@@ -1113,24 +1113,24 @@
 b_status',)%0A
-
     exclude 
@@ -1163,16 +1163,51 @@
 content'
+, 'md_last_edited', 'md_last_autor'
 )%0Aadmin.

Exclude fields from admin backend