Created
May 12, 2018 06:07
-
-
Save elcolie/e19e4f934acbf95e6f7d8d8e997dbca0 to your computer and use it in GitHub Desktop.
Example save FieldField in Django
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
class Voucher(AbstractThumbnail, AbstractTimestamp): | |
... | |
image = models.ImageField(default='uc.png', upload_to='vouchers') | |
def give_voucher(...): | |
filename = str(uuid.uuid4()) + '.jpg' | |
with open(str(settings.BASE_DIR('apps/vouchers/S__10838070.jpg')), 'rb') as file: | |
data = File(file) | |
voucher.image.save(filename, data, True) | |
voucher.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment