Please help me figure out how to display the downloaded pictures in the django admin panel
here's a model
class Product(models.Model): product_name=models.CharField(max_length=900) product_image = models.ImageField(upload_to=get_image_path, blank=True, null=True) product_price=models.FloatField(max_length=10) product_discaunt=models.CharField(max_length=5, blank=True) product_category=models.CharField(max_length=1000) product_discription=models.TextField(max_length=1000) def __unicode__(self): return self.product_discription def __unicode__(self): return self.product_category def __unicode__(self): return self.product_name def image_img(self): if self.product_image: return u'<a href="{0}" target="_blank"><img src="{0}" width="100"/></a>'.format(self.product_image.url) else: return '(no picture)' image_img.short_description = 'Picture' image_img.allow_tags = True
here are the urls
urlpatterns = [ url(r'^store/', include('store.urls')), url(r'^admin/', admin.site.urls), url(r'^media/(?P<path>.*)$', serve, { 'document_root': settings.MEDIA_ROOT, }), ]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
here is admin.py
class ProductAdmin(admin.ModelAdmin): list_display = ('product_name','product_image', 'image_img','product_price', 'product_category', ) readonly_fields = ['image_img',] fields=('product_name','product_image', 'image_img','product_price', 'product_category', ) """ def image_tag(self, obj): return '<img src="%s">' % obj.product_image.url image_tag.allow_tags = True """ admin.site.register(Product, ProductAdmin)
here are the settings.py
_PATH = os.path.abspath(os.path.dirname(__file__)) MEDIA_ROOT = os.path.join(_PATH, 'media') MEDIA_URL = '/media/' STATIC_URL = '/static/' """ STATICFILES_DIRS = ( os.path.join(_PATH, 'static'), ) """ STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', ) ADMIN_MEDIA_PREFIX = '/static/admin/'
that's actually a mistake
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/media/img/i-should-buy-a-boat.jpg
Raised by: django.contrib.staticfiles.views.serve
:8000
? - Ivan Semochkin