0

Seemingly trivial question, but I'm stuck.

I'm trying to add add a photo to a model's ImageField when I create the model. But I don't know how to specify the photo. Do I specify the path, or a photo object?

class MyModel(models.Model):
    img = models.ImageField()

# I tried these, none works
from PIL import Image
MyModel.objects.create(img='img.jpg')
MyModel.objects.create(img=Image.open('img.jpg'))
MyModel.objects.create(img=open('img.jpg', 'r'))
MyModel.objects.create(img=open('img.jpg', 'w'))
Valachio
  • 1,025
  • 2
  • 18
  • 40

0 Answers0