Last active
August 29, 2015 14:25
-
-
Save gengue/202e38689dab7d29016b to your computer and use it in GitHub Desktop.
Image and price display with placehold.it in django admin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClothAdmin(admin.ModelAdmin): | |
list_display = ('name', 'category', 'description', 'price_display', 'image_display',) | |
search_fields = ('name', 'category', 'description', 'price',) | |
list_filter = ('category',) | |
def price_display(self, obj): | |
return '${:20,d}'.format(obj.price) | |
price_display.short_description = 'precio' | |
price_display.admin_order_field = 'price' | |
def image_display(self, obj): | |
if obj.image: | |
return '<img src="%s" width="60px" height="60px">' % (obj.image.url) | |
else: | |
return '<img src="%s" width="60px" height="60px">' % ('http://placehold.it/60x60') | |
image_display.allow_tags = True | |
image_display.admin_order_field = 'imagen' | |
image_display.short_description = 'Imagen' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment