31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
from django.contrib import admin
|
|
from django.utils.html import format_html
|
|
from import_export.admin import ImportExportModelAdmin
|
|
|
|
from apps.orders.models import Product, ShoppingCar
|
|
|
|
@admin.register(Product)
|
|
class ProductAdmin(admin.ModelAdmin):
|
|
search_fields = ['name', 'description']
|
|
list_display = ('name', 'foto', 'price', 'is_active')
|
|
list_filter = ('is_active',)
|
|
fields = ('name', 'imagen', 'description', 'price', 'is_active')
|
|
|
|
def foto(self, obj):
|
|
if obj.imagen:
|
|
return format_html('<img style="width: 100px; height:auto;" src="{}" />'.format(obj.imagen.url))
|
|
return ""
|
|
|
|
@admin.register(ShoppingCar)
|
|
class ShoppingCarAdmin(admin.ModelAdmin):
|
|
search_fields = ['name', 'description']
|
|
list_display = ('item', 'foto', 'price')
|
|
fields = ('name', 'imagen', 'description', 'price')
|
|
|
|
def carrito(self, obj):
|
|
return ""
|
|
|
|
def foto(self, obj):
|
|
if obj.item.imagen:
|
|
return format_html('<img style="width: 100px; height:auto;" src="{}" />'.format(obj.imagen.url))
|
|
return "" |