124 lines
4.3 KiB
Python
124 lines
4.3 KiB
Python
from django.contrib import admin
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django.utils.html import format_html
|
|
from .models import (
|
|
Product, Category, FursuitGallery, GalleryImage,
|
|
DesignTemplate, CustomerDesign, Order, OrderProgress,
|
|
Cart, CartItem, ShippingAddress, Checkout,
|
|
ProductType, ProductImage, ProductVariant, CustomDesign,
|
|
PayPalPayment, PaymentError
|
|
)
|
|
|
|
@admin.register(Category)
|
|
class CategoryAdmin(admin.ModelAdmin):
|
|
list_display = ['name', 'slug', 'parent']
|
|
list_filter = ['parent']
|
|
search_fields = ['name']
|
|
prepopulated_fields = {'slug': ('name',)}
|
|
|
|
@admin.register(ProductType)
|
|
class ProductTypeAdmin(admin.ModelAdmin):
|
|
list_display = ['name', 'has_sizes', 'has_colors', 'has_custom_design', 'requires_measurements']
|
|
list_filter = ['has_sizes', 'has_colors', 'has_custom_design', 'requires_measurements']
|
|
search_fields = ['name']
|
|
|
|
class ProductImageInline(admin.TabularInline):
|
|
model = ProductImage
|
|
extra = 1
|
|
|
|
class ProductVariantInline(admin.TabularInline):
|
|
model = ProductVariant
|
|
extra = 1
|
|
|
|
@admin.register(Product)
|
|
class ProductAdmin(admin.ModelAdmin):
|
|
list_display = ['name', 'category', 'price', 'stock', 'available', 'created']
|
|
list_filter = ['available', 'category', 'product_type', 'created']
|
|
search_fields = ['name', 'description']
|
|
prepopulated_fields = {'slug': ('name',)}
|
|
inlines = [ProductImageInline, ProductVariantInline]
|
|
date_hierarchy = 'created'
|
|
|
|
@admin.register(CustomDesign)
|
|
class CustomDesignAdmin(admin.ModelAdmin):
|
|
list_display = ['product', 'customer', 'status', 'created']
|
|
list_filter = ['status', 'created']
|
|
search_fields = ['product__name', 'customer__username']
|
|
date_hierarchy = 'created'
|
|
|
|
@admin.register(DesignTemplate)
|
|
class DesignTemplateAdmin(admin.ModelAdmin):
|
|
list_display = ['name', 'created_at']
|
|
search_fields = ['name', 'description']
|
|
|
|
@admin.register(CustomerDesign)
|
|
class CustomerDesignAdmin(admin.ModelAdmin):
|
|
list_display = ['user', 'name', 'created_at']
|
|
search_fields = ['user__username', 'name']
|
|
date_hierarchy = 'created_at'
|
|
|
|
class OrderProgressInline(admin.TabularInline):
|
|
model = OrderProgress
|
|
extra = 1
|
|
|
|
@admin.register(Order)
|
|
class OrderAdmin(admin.ModelAdmin):
|
|
list_display = ['id', 'user', 'product', 'status', 'payment_method', 'total_price', 'created_at']
|
|
list_filter = ['status', 'payment_method', 'created_at']
|
|
search_fields = ['user__username', 'product__name']
|
|
inlines = [OrderProgressInline]
|
|
date_hierarchy = 'created_at'
|
|
|
|
class CartItemInline(admin.TabularInline):
|
|
model = CartItem
|
|
extra = 1
|
|
|
|
@admin.register(Cart)
|
|
class CartAdmin(admin.ModelAdmin):
|
|
list_display = ['user', 'created_at', 'updated_at']
|
|
search_fields = ['user__username']
|
|
inlines = [CartItemInline]
|
|
date_hierarchy = 'created_at'
|
|
|
|
@admin.register(ShippingAddress)
|
|
class ShippingAddressAdmin(admin.ModelAdmin):
|
|
list_display = ['user', 'first_name', 'last_name', 'city', 'country']
|
|
list_filter = ['country']
|
|
search_fields = ['user__username', 'first_name', 'last_name', 'city']
|
|
|
|
@admin.register(Checkout)
|
|
class CheckoutAdmin(admin.ModelAdmin):
|
|
list_display = ['user', 'status', 'payment_method', 'created_at']
|
|
list_filter = ['status', 'payment_method']
|
|
search_fields = ['user__username']
|
|
date_hierarchy = 'created_at'
|
|
|
|
@admin.register(PayPalPayment)
|
|
class PayPalPaymentAdmin(admin.ModelAdmin):
|
|
list_display = ['order', 'payment_id', 'status', 'amount', 'currency', 'created_at']
|
|
list_filter = ['status', 'currency']
|
|
search_fields = ['payment_id', 'order__id']
|
|
date_hierarchy = 'created_at'
|
|
|
|
@admin.register(PaymentError)
|
|
class PaymentErrorAdmin(admin.ModelAdmin):
|
|
list_display = ['order', 'error_code', 'created_at']
|
|
search_fields = ['order__id', 'error_code', 'error_message']
|
|
date_hierarchy = 'created_at'
|
|
|
|
@admin.register(FursuitGallery)
|
|
class FursuitGalleryAdmin(admin.ModelAdmin):
|
|
list_display = ['name', 'created_at']
|
|
search_fields = ['name', 'description']
|
|
prepopulated_fields = {'slug': ('name',)}
|
|
|
|
class GalleryImageInline(admin.TabularInline):
|
|
model = GalleryImage
|
|
extra = 1
|
|
|
|
@admin.register(GalleryImage)
|
|
class GalleryImageAdmin(admin.ModelAdmin):
|
|
list_display = ['gallery', 'title', 'order']
|
|
list_filter = ['gallery']
|
|
search_fields = ['gallery__name', 'title']
|