admin.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # admin.py
  2. from django.contrib import admin
  3. from .models import Product, AttributeScore, CategoryAttributeRule
  4. # -------------------------
  5. # Product Admin
  6. # -------------------------
  7. @admin.register(Product)
  8. class ProductAdmin(admin.ModelAdmin):
  9. list_display = ('sku', 'title', 'category', 'created_at', 'updated_at')
  10. search_fields = ('sku', 'title', 'category')
  11. list_filter = ('category', 'created_at', 'updated_at')
  12. readonly_fields = ('created_at', 'updated_at')
  13. ordering = ('-created_at',)
  14. # -------------------------
  15. # AttributeScore Admin
  16. # -------------------------
  17. @admin.register(AttributeScore)
  18. class AttributeScoreAdmin(admin.ModelAdmin):
  19. list_display = ('product', 'score', 'max_score', 'processing_time', 'created_at')
  20. search_fields = ('product__sku', 'product__title')
  21. list_filter = ('created_at',)
  22. readonly_fields = ('created_at',)
  23. ordering = ('-created_at',)
  24. autocomplete_fields = ('product',) # makes it easier to select products in large DB
  25. # -------------------------
  26. # CategoryAttributeRule Admin
  27. # -------------------------
  28. @admin.register(CategoryAttributeRule)
  29. class CategoryAttributeRuleAdmin(admin.ModelAdmin):
  30. list_display = ('category', 'attribute_name', 'is_mandatory', 'data_type')
  31. search_fields = ('category', 'attribute_name')
  32. list_filter = ('category', 'is_mandatory', 'data_type')
  33. ordering = ('category', 'attribute_name')