I have in models.py
:
class Item(models.Model):
image_file = models.ImageField(upload_to='images')
image_url = models.URLField()
I want django automatically download and locally save image from image_url
and "connect" it with image_file
How it should act:
- I Paste
https://docs.djangoproject.com/s/img/site/hdr_logo.gif
intoimage_url
field in admin - Click "save"
- In templates write
<img src="{{ item.image_file.url }}">
. It shows image from my server, notdjangoproject.com
What I've tried:
I've overwritten save
method of Item
class. I saved image locally via urllib
, but I am stuck on connecting this saved image with image_file
field