from django.contrib import admin

from models import (
  Category,
  Product,
)
from forms import ProductAdminForm


class ProductAdmin(admin.ModelAdmin):
  """Admin class for Product model
  """
  form = ProductAdminForm

  # sets values for how the admin site lists products
  list_display = (
    'name',
    'price',
    'old_price',
    'created_at',
    'updated_at',
  )
  list_display_links = ('name',)
  list_per_page = 50
  ordering = ['-created_at']
  search_fields = [
    'name',
    'description',
    'meta_keywords',
    'meta_description'
  ]
  exclude = ('created_at', 'updated_at',)

  # sets up slug to be generated from product name
  prepopulated_fields = {
    'slug' : ('name',)
  }

class CategoryAdmin(admin.ModelAdmin):
  """Admin class for Category model
  """
  #sets up values for how admin site lists categories
  list_display = (
    'name',
    'created_at',
    'updated_at',
  )
  list_display_links = ('name',)
  list_per_page = 20
  ordering = ['name']
  search_fields = [
    'name',
    'description',
    'meta_keywords',
    'meta_description'
  ]
  exclude = ('created_at', 'updated_at',)

  # sets up slug to be generated from category name
  prepopulated_fields = {
    'slug' : ('name',)
  }

# Register your models with the admin site
admin.site.register(Product, ProductAdmin)
admin.site.register(Category, CategoryAdmin)
