from django.contrib import admin
from django.utils.safestring import mark_safe
from customer.models import Owner, Dog, Breed, SubBreed

class OwnerAdmin(admin.ModelAdmin):
    """
    Owner ModelAdmin.
    """
    search_fields = ['name']


class BreedAdmin(admin.ModelAdmin):
    """
    Breed ModelAdmin.
    """
    search_fields = ['name']


class SubBreedAdmin(admin.ModelAdmin):
    """
    SubBreed ModelAdmin.
    """
    search_fields = ['name', 'breed__name']
    autocomplete_fields = ['breed']
    list_display = ['name', 'breed']


class DogAdmin(admin.ModelAdmin):
    """
    Dog ModelAdmin.
    """
    search_fields = ['name', 'owner__name']
    autocomplete_fields = ['owner', 'breed', 'sub_breed']
    list_display = ['name', 'owner', 'breed', 'sub_breed', 'img_photo']

    def img_photo(self, obj):
        """
        Render the dog's photo.
        """
        return mark_safe('<img src="%s" width="70">' % obj.photo.url)


admin.site.register(Dog, DogAdmin)
admin.site.register(Owner, OwnerAdmin)
admin.site.register(Breed, BreedAdmin)
admin.site.register(SubBreed, SubBreedAdmin)
[(43, 'django.contrib.admin.site.register', 'admin.site.register', False, 'from django.contrib import admin\n'), (44, 'django.contrib.admin.site.register', 'admin.site.register', False, 'from django.contrib import admin\n'), (45, 'django.contrib.admin.site.register', 'admin.site.register', False, 'from django.contrib import admin\n'), (46, 'django.contrib.admin.site.register', 'admin.site.register', False, 'from django.contrib import admin\n'), (40, 'django.utils.safestring.mark_safe', 'mark_safe', False, 'from django.utils.safestring import mark_safe\n')]