hello i want to make upload image in admin django but when i use media_root and media url image can not upload. this is model.py
class Product(models.Model):
category = models.ForeignKey('Category')
userprofile = models.ForeignKey('UserProfile')
title = models.CharField(max_length=50)
price = models.IntegerField()
image = models.ImageField(upload_to=settings.MEDIA_ROOT)
description = models.TextField()
created_date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title;
setting.py
MEDIA_ROOT = '/static/images/upload/'
MEDIA_URL = '/upload/'
view.py
def home(request):
posts = Product.objects.filter(created_date__isnull=False)
return render(request, 'kerajinan/product_list.html', {
'posts' : posts,
'categories' : Category.objects.all(),
})
and this is tamplate product.html
<img src="{{post.image.url}}" alt="" />
can you help me solve this problem?