Answer the question
In order to leave comments, you need to log in
Why are images not showing up in the Django admin?
For some reason, pictures in the admin panel are not loaded, instead of them, just squares.
And yet, how can I change the name of the get_photo column to something else?
admin.py
class NewsAdmin(admin.ModelAdmin):
list_display = ('id', 'title', 'category', 'pub_date', 'is_published', 'get_photo')
list_display_links = ('id', 'title')
search_fields = ('id', 'title', 'content')
list_editable = ('is_published', 'category')
list_filter = ('pub_date','is_published',)
def get_photo(self, obj):
if obj.photo:
return mark_safe(f'<img src="{obj.photo.url}" width="75px">')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question