Last active
June 19, 2020 01:39
-
-
Save walison17/baa366e7ae76ab43e6fd139bda2936b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from django.core.files.storage import default_storage | |
# obj seria uma instância de algum modelo com um FileField ou ImageField | |
# chamado img. | |
with obj.img.open("r") as img: | |
_, ext = os.path.splitext(img.file) | |
obj.img.save(f"novo-nome-{obj.pk}.{ext}", img.file, save=False) | |
default_storage.delete(img.name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment