from files.models import File, Category, Type
from django.contrib import admin
from django.contrib.auth.models import User
from django_firefogg.forms import FirefoggInput
from django import forms

class filesForm(forms.ModelForm):
  file = forms.FileField(label='Upload File',
                              required=False,
                              widget=FirefoggInput({'passthrough': True}))
  exclude = ('info',)
  class Meta:
    model = File

class FilesAdmin(admin.ModelAdmin):
  list_display = ('title', 'type', 'file_date')
  list_filter = ('categories', 'added', 'file_date')
  ordering = ('-file_date',)
  search_fields = ('title', 'description')
  exclude = ('userID',)
  form = filesForm

  def save_model(self, request, obj, form, change):
    if not change:
        obj.userID = request.user
    obj.save()

class CategoryAdmin(admin.ModelAdmin):
  search_fields = ('name',)

class TypeAdmin(admin.ModelAdmin):
  ordering = ('name',)

admin.site.register(File, FilesAdmin) 
admin.site.register(Category, CategoryAdmin)
admin.site.register(Type, TypeAdmin)
#admin.site.register(SliderImage)
