Source

gnocchi-catalogue / catalogue / admin.py

Diff from to

File catalogue/admin.py

 from gnocchi_catalogue import models
 from gnocchi_tools.admin import InlineAttributeAdmin
 
-class InlinePriceBreakAdmin( admin.TabularInline ):
+class InlinePriceBreakAdmin(admin.TabularInline):
     model = models.PriceBreak
+    extra = 0
 
-class InlineVariantAdmin( admin.TabularInline ):
+class InlineVariantAdmin(admin.TabularInline):
     model = models.ProductVariant
+    extra = 0
 
-class InlineProductImageAdmin( admin.TabularInline ):
-    model = models.ProductImage
+class InlineImageAdmin(admin.TabularInline):
+    model = models.Image
+    extra = 0
 
-class ProductAdmin( admin.ModelAdmin ):
-    list_display = ( 'title', 'price', 'short_description', 'get_codes', )
-    list_filter = ( 'price', )
-    filter_horizontal = ( 'related_products', )
+class InlineSubProductAdmin(admin.TabularInline):
+    model = models.SubProduct
+    extra = 0
+
+class ProductAdmin(admin.ModelAdmin):
+    list_display = ('title', 'price', 'short_description', 'get_codes',)
+    list_filter = ('price',)
+    filter_horizontal = ('related_products',)
     inlines = [
+        InlineSubProdictAdmin,
         InlineVariantAdmin,
-        InlineProductImageAdmin,
+        InlineImageAdmin,
         InlinePriceBreakAdmin,
         InlineAttributeAdmin,
     ]
     def get_codes(self, obj):
-        return u', '.join(obj.productvariant_set.values_list('sku', flat=True ))
+        return u', '.join(obj.productvariant_set.values_list('sku', flat=True))
     get_codes.short_description = 'Codes'
 
-
-admin.site.register( models.Product, ProductAdmin )
+admin.site.register(models.Product, ProductAdmin)