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, 0, 43, 34), 'django.contrib.admin.site.register', 'admin.site.register', ({(43, 20, 43, 23): 'Dog', (43, 25, 43, 33): 'DogAdmin'}, {}), '(Dog, DogAdmin)', False, 'from django.contrib import admin\n'), ((44, 0, 44, 38), 'django.contrib.admin.site.register', 'admin.site.register', ({(44, 20, 44, 25): 'Owner', (44, 27, 44, 37): 'OwnerAdmin'}, {}), '(Owner, OwnerAdmin)', False, 'from django.contrib import admin\n'), ((45, 0, 45, 38), 'django.contrib.admin.site.register', 'admin.site.register', ({(45, 20, 45, 25): 'Breed', (45, 27, 45, 37): 'BreedAdmin'}, {}), '(Breed, BreedAdmin)', False, 'from django.contrib import admin\n'), ((46, 0, 46, 44), 'django.contrib.admin.site.register', 'admin.site.register', ({(46, 20, 46, 28): 'SubBreed', (46, 30, 46, 43): 'SubBreedAdmin'}, {}), '(SubBreed, SubBreedAdmin)', False, 'from django.contrib import admin\n'), ((40, 15, 40, 69), 'django.utils.safestring.mark_safe', 'mark_safe', ({(40, 25, 40, 68): '(\'<img src="%s" width="70">\' % obj.photo.url)'}, {}), '(\'<img src="%s" width="70">\' % obj.photo.url)', False, 'from django.utils.safestring import mark_safe\n')]