from django.contrib import admin
from tagulous.admin import TagModelAdmin

from django_admin_listfilter_dropdown.filters import DropdownFilter, RelatedDropdownFilter, ChoiceDropdownFilter

from . import models
from . import forms

# Register your models here.


def model_admin_callable(co):
    return co.company_name

class ProductAdmin(admin.ModelAdmin):
    form = forms.ProductTagForm
    list_display = ('name', 'category', 'sourcing_date', 'company', 'active' )
    list_filter = (
        ('company', RelatedDropdownFilter),
        ('tags', RelatedDropdownFilter),
        ('category', RelatedDropdownFilter),
        ('attributes', RelatedDropdownFilter)
    )

    search_fields = ('name', 'sku', 'description')

class CategoryTagAdmin(TagModelAdmin):
    form = forms.CategoryTagForm
    list_display = ('label', 'name', 'official', 'level')
    search_fields = ('label', 'name', 'slug')


admin.site.register(models.Product, ProductAdmin)
admin.site.register(models.TreeTag)
admin.site.register(models.CategoryTag, CategoryTagAdmin)
admin.site.register(models.AttributeTag)
