Good day PA.
How do I properly display thumbnails of user uploaded files in my admin site?
I'm got an error message that the file does not exist, when I tried to preview the image.
Below are codes from my app. You can go further to take a look at my entire code.
Thank you.
--in my settings.py--
MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'ural/media')
---in my models.py--
class Ad_form_home(models.Model): ref = models.CharField(primary_key=True,db_index=True,max_length=200) image = models.ImageField(null=True, blank=True, upload_to="images/%Y/%m/%d/")
def __str__(self):
return f"{self.ref}"
def image_view(self):
return mark_safe("<img src='media/images/' width='100' height='100' />" % (self.image))
--in my admin.py--
class Ad_form_homeAdmin(admin.ModelAdmin):
fieldset = [
('Successful payments',
{'fields': ['ref']},
{'fields': ['image_view']},
{'fields': ['image']}),
]
list_display = ('ref', 'image_view', 'image')
--in my urls.py--
path(os.getenv('SECRET_ADMIN_URL') + '/admin/', admin.site.urls), ]+static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)