0

I would like to deploy an image to my page using Django, still in a debig mode. I created a model for the image along some other fields, and all the information is migrated to the database except the image which is storaged in the directory folder for /media/. How can i upload this image to the db and deploy it from there?

class Products(models.Model):

title = models.CharField(max_length=30)
image = models.ImageField(blank=True, null=True)

def __str__(self):
    return self.title
  • Possible duplicate of [Django: Storing Images Database](https://stackoverflow.com/questions/46460861/django-storing-images-database) – ipaleka Jul 06 '19 at 00:13

1 Answers1

0

I would recommend you not to store the image in db instead in the folder. But also if you want, use BinaryField

class Product(models.Model):
    title = models.CharField(max_length=30)
    image = models.BinaryField(blank=True, null=True)

`   def __str__(self):
       return self.title
Saroj Rai
  • 1,419
  • 14
  • 13