Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question