from django.contrib import admin
from models import *

from datetime import datetime, timedelta
import settings


class ClassifiedAdmin(admin.ModelAdmin):
    list_display = ("copy", "subcategory")
    list_filter = ("featured", "subcategory")
    search_fields = ("title", "copy")


"""
    def save_model(self, request, obj, form, change):
        if not change:
            obj.owner = request.user
        if not change:
            if obj.featured:
                obj.featured_until=(datetime.now()+timedelta(days=settings.CLASSIFIED_LENGTH))
        obj.save()
"""

admin.site.register(Classified, ClassifiedAdmin)


class CategoryAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("name",)}


admin.site.register(Category, CategoryAdmin)


class SubcategoryAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("name",)}


admin.site.register(Subcategory, SubcategoryAdmin)
admin.site.register(ClassifiedsUpload)
"""
class ClassifiedPhotoAdmin(admin.ModelAdmin):
    list_display = ('title', 'created', 'published', 'tags', 'view_count', 'admin_thumbnail')
    fieldsets=[
        (None, {'fields': ['title', 'description', 'image','tags','primary']}),
    ]    
 

    def save_model(self, request, obj, form, change):
        if not change:
            obj.owner = request.user
        if not obj.published:
            obj.published=True
            obj.pub_date=datetime.now()
        obj.save()

admin.site.register(ClassifiedPhoto, ClassifiedPhotoAdmin)
"""
