24👍
✅
Finally I found the answer.
from django.core.files import File
f = File(open(os.path.join(IMPORT_DIR, 'fotos', photo), 'rb'))
p = Photo(name=f.name, image=f, parent=supply.supply_ptr)
name = str(uuid1()) + os.path.splitext(f.name)[1]
p.image.save(name, f)
p.save()
7👍
If using Python 3 one adjustment is needed – change ‘r’ to ‘rb’:
f = File(open(os.path.join(IMPORT_DIR, 'fotos', photo), 'rb'))
- Psycopg2 cannot connect to docker image
- How to download a filefield file in django view
- Enable PK based filtering in Django Graphene Relay while retaining Global IDs
- Error loading MySQLdb module: libmysqlclient.so.20: cannot open shared object file: No such file or directory
Source:stackexchange.com