1👍
Actually, I would not create a QR code for the Device
s, at least not proactively.
We can construct such QR code on demand, in a view where we want to obtain the QR code. Indeed, such view would look like:
from io import BytesIO
from django.http import HttpResponse
from qrcode import make
from qrcode.image.svg import SvgPathImage
def qr_code_for_device(request, pk):
device = get_object_or_404(Device, pk=pk)
buffer = BytesIO()
image = make(device.screen_url, image_factory=SvgPathImage)
image.save(buffer)
return HttpResponse(buffer.getvalue(), content_type='image/svg+xml')
when visiting the view thus for a certain device, it will return an SVG image with the QR code for the screen_url
of that device.
If later the screen_url
of the device changes, requesting the qr code with a new request will thus render a QR code with the updated screen_url
. It will also save a lot of diskspace, since the images generated only exist in memory until the response is send. Finally performance is likely not an issue here, since QR codes are generated quite efficiently, and actually opening and loading the file to send this as a response is probably comparable in terms of performance, but very likely not that much more efficient.