9👍
✅
settings.py
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
)+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += staticfiles_urlpatterns()
models.py
class Activity(models.Model):
...
thumbnail = models.ImageField(upload_to="thumbs/", blank=True, null=True)
def image_(self):
return '<a href="/media/{0}"><img src="/media/{0}"></a>'.format(self.thumbnail)
image_.allow_tags = True
class AdminName(admin.ModelAdmin):
.........
list_display = ('image_',)
Source:stackexchange.com