I have few questions please guide on these
- I am try to stroe images in database but they are getting store in media directory
2.The corresponding url is stored in the db column but I need actual image to be stored in the
db
please advice
I have few questions please guide on these
This is not a good idea to store an image in DB instead media
folder. But you can use BinaryField for this:
model.py
class MyModel(model.Model):
image = models.BinaryField(blank=True)
view.py
def image(request):
image_file = request.FILES['image_file'].file.read()
MyModel.objects.create(image=image_file)
It is not possible to store the image itself in a database. You need to convert it to binary and store. You can use BytesIO. Here is a link which similar question explaining how to use it