V
V
Vova1357982021-04-20 20:05:27
Django
Vova135798, 2021-04-20 20:05:27

How to display images in Django admin?

How to display images in the admin panel?

models.py

class Author(models.Model):
    name = models.CharField(max_length=100)
    date_of_birth = models.DateField(null=True, blank=True)
    date_of_death = models.DateField('died', null=True, blank=True)
    photo = models.ImageField(upload_to='photos/%y/%m/%d/', blank=True,verbose_name='Фотография')

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = 'Автор'
        verbose_name_plural = 'Авторы'


admin.py

class AuthorAdmin(admin.ModelAdmin):
    list_display = ('photo', 'name',)


admin.site.register(Author, AuthorAdmin)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maksam07, 2021-04-20
@maksam07

For example like this: https://stackoverflow.com/a/16307554

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question