In a Django website of mine, users upload photos and others comment on them. Currently, the whole uploading process is a blocking call. So instead, I want to move it to a celery queue and execute it asynchronously. For that, I simply call the following from views.py:
photo = form.cleaned_data.get('photo',None)
upload_photo.delay(photo, request.user.id)
And then in tasks.py, I have:
@celery_app1.task(name='tasks.upload_photo')
def upload_photo(photo_obj, user_id):
photo = Photo.objects.create(image_file = photo_obj, owner_id=user_id)
Now this, predictably, gives me an EncodeError: <InMemoryUploadedFile: temp.jpg (image/jpeg)> is not JSON serializable. So what's the right pattern to follow here in order to do the heavy lifting in an aysnc task? An illustrative example would be very helpful.
P.s. in case it matters to the answerer, I'm looking for a solution with no JS involvement.