-1

How would I add the image belonging to this model on the detail page of that model in the Admin Page? The image can be on the right side of the data/text or below the data/text/

from django.db import models


# Create your models here.

class Gallery3(models.Model):
    class Meta:
        verbose_name = "Vintago Upload"

    CATEGORIES = (
    ('Meubels', 'Meubels'),
    ('Vazen', 'Vazen'),
    ('Schilderijen', 'Schilderijen'),
)
    title = models.CharField(max_length=100)
    category = models.CharField(max_length=10, choices=CATEGORIES, default='Meubels')
    description = models.CharField(max_length=255, blank=True)
    document = models.ImageField(upload_to='images',null=True)
    price= models.DecimalField(max_digits=10, decimal_places=2)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.title


    #def get_absolute_url(self):
     #   return reverse('gallery_detail', kwargs={'pk': self.pk})
BartD
  • 29
  • 1
  • 8
  • Possible duplicate of [Django Admin Show Image from Imagefield](https://stackoverflow.com/questions/16307307/django-admin-show-image-from-imagefield) – Lemayzeur Jun 04 '18 at 13:43

1 Answers1

-1
def image_img(self):
    if self.image:
        return marksafe('<img src="%s" />' % self.document)
    else:
        return '(no image)'

image_img.short_description = 'Thumb'

# and in your admin.py add:
list_display= ('image_img','product',)
readonly_fields = ('image_img',)

# and for adding it in the 'Edit mode' of your admin panel in your admin.py add:
fields = ( 'image_img', )
kuloo
  • 16
  • 1
  • 1
    While this code snippet may solve the problem, it doesn't explain why or how it answers the question. Please [include an explanation for your code](//meta.stackexchange.com/q/114762/269535), as that really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Luca Kiebel Jun 04 '18 at 13:43