69 lines
2.3 KiB
Python
69 lines
2.3 KiB
Python
from django.contrib import admin
|
|
from .models import Category, Website, Product, ProductPrice, ProductPriceHistory, ComparisonTag, ComparisonTagItem
|
|
|
|
|
|
@admin.register(Category)
|
|
class CategoryAdmin(admin.ModelAdmin):
|
|
list_display = ['id', 'name', 'slug', 'parent', 'sort_order', 'created_at']
|
|
list_filter = ['parent']
|
|
search_fields = ['name', 'slug']
|
|
prepopulated_fields = {'slug': ('name',)}
|
|
ordering = ['sort_order', 'id']
|
|
|
|
|
|
@admin.register(Website)
|
|
class WebsiteAdmin(admin.ModelAdmin):
|
|
list_display = ['id', 'name', 'url', 'category', 'rating', 'is_verified', 'sort_order']
|
|
list_filter = ['category', 'is_verified']
|
|
search_fields = ['name', 'url']
|
|
ordering = ['sort_order', 'id']
|
|
|
|
|
|
@admin.register(Product)
|
|
class ProductAdmin(admin.ModelAdmin):
|
|
list_display = ['id', 'name', 'category', 'created_at', 'updated_at']
|
|
list_filter = ['category']
|
|
search_fields = ['name', 'description']
|
|
ordering = ['-created_at']
|
|
|
|
|
|
@admin.register(ProductPrice)
|
|
class ProductPriceAdmin(admin.ModelAdmin):
|
|
list_display = ['id', 'product', 'website', 'price', 'original_price', 'in_stock', 'last_checked']
|
|
list_filter = ['website', 'in_stock', 'currency']
|
|
search_fields = ['product__name', 'website__name']
|
|
ordering = ['-updated_at']
|
|
|
|
|
|
@admin.register(ProductPriceHistory)
|
|
class ProductPriceHistoryAdmin(admin.ModelAdmin):
|
|
list_display = ['id', 'product', 'website', 'price', 'recorded_at']
|
|
list_filter = ['website']
|
|
search_fields = ['product__name', 'website__name']
|
|
ordering = ['-recorded_at']
|
|
|
|
|
|
class ComparisonTagItemInline(admin.TabularInline):
|
|
model = ComparisonTagItem
|
|
extra = 1
|
|
autocomplete_fields = ["product"]
|
|
ordering = ["-is_pinned", "sort_order", "id"]
|
|
|
|
|
|
@admin.register(ComparisonTag)
|
|
class ComparisonTagAdmin(admin.ModelAdmin):
|
|
list_display = ['id', 'name', 'slug', 'is_active', 'sort_order', 'created_at']
|
|
list_filter = ['is_active']
|
|
search_fields = ['name', 'slug']
|
|
prepopulated_fields = {'slug': ('name',)}
|
|
ordering = ['sort_order', 'id']
|
|
inlines = [ComparisonTagItemInline]
|
|
|
|
|
|
@admin.register(ComparisonTagItem)
|
|
class ComparisonTagItemAdmin(admin.ModelAdmin):
|
|
list_display = ['id', 'tag', 'product', 'is_pinned', 'sort_order', 'created_at']
|
|
list_filter = ['tag', 'is_pinned']
|
|
search_fields = ['product__name', 'tag__name']
|
|
ordering = ['-created_at']
|