Reputation: 11533
When I try to save an image object to an ImageField I get the following error:
get_available_name() got an unexpected keyword argument 'max_length'
The code looks like this:
imagen_url = form.cleaned_data['imagen_url']
respuesta = requests.get(imagen_url)
imagen = Image.open(StringIO(respuesta.content))
stringio_obj = StringIO()
imagen.save(stringio_obj, format="JPEG")
final_image = stringio_obj.getvalue()
carta.creador = request.user
carta.ultima_revision = datetime.today()
carta.save()
print("carta_id: %s" % carta.id) # Works correctly till here
archivo_imagen = ContentFile(final_image, "0_" + carta.nombre) # Guarda la original con un 0 adelante
carta.imagen_base.save("0_" + carta.nombre, archivo_imagen, save=True)
When I try ty to save the ContentFile
object to the model`s ImageField, it doesn't work. It used to work in a lower version of Django, but since I shifted to django 1.10, it stopped working.
The model is simple, it looks like this:
def ubicar_img_base(instance, filename):
nombre_archivo = "0_" + slugify(instance.nombre) + ".jpeg"
path = "/".join([instance.grupo.nombre, nombre_archivo])
return path
class CartaMagicPy(models.Model):
imagen_base = models.ImageField(null=True, upload_to=ubicar_img_base)
Any advice will help
Upvotes: 1
Views: 653
Reputation: 11533
Ok, hope this is useful to someone sometime: I solved it updating boto
and storages
. This would sound familiar to you if you use amazon AWS.
Upvotes: 4