Skip to content

Instantly share code, notes, and snippets.

@gengue
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gengue/202e38689dab7d29016b to your computer and use it in GitHub Desktop.
Save gengue/202e38689dab7d29016b to your computer and use it in GitHub Desktop.
Image and price display with placehold.it in django admin
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