Skip to content

Instantly share code, notes, and snippets.

@erickgnavar
Last active October 4, 2016 14:09
Show Gist options
  • Save erickgnavar/5a9dd41ac52950975439df6055ec2881 to your computer and use it in GitHub Desktop.
Save erickgnavar/5a9dd41ac52950975439df6055ec2881 to your computer and use it in GitHub Desktop.
from StringIO import StringIO
from django.core.files.uploadedfile import InMemoryUploadedFile
from qrcode import QRCode
qr_code = QRCode(version=1, box_size=10, border=4)
qr_code.add_data('qr content')
qr_code.make(fit=True)
image = qr_code.make_image()
image_io = StringIO()
image.save(image_io, image.kind)
tmp = InMemoryUploadedFile(image_io, None, 'test-name', 'image/png', image_io.len, None)
product = Product()
# product.qr_code is a ImageField
product.qr_code = tmp
product.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment