0

I have this in my models.py:

class MyModel(models.Model)
    imgA = ThumbnailerImageField(upload_to="site_images/",
                                 null=True, blank=True)
    imgB = ThumbnailerImageField(upload_to="site_images/",
                                 null=True, blank=True)

and I want to copy imgA to imgB so I tried:

def copy_thumbnailer():
    obj = MyModel.objects.get(id=1)
    obj.imgB = obj.imgA
    obj.save()

The function run with no errors, but the ThumbnailerImageField it's not copied. There's some way to achieve this?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Adrian Lopez
  • 2,601
  • 5
  • 31
  • 48

1 Answers1

0

SOLUTION: You must use get_thumbnailer() method. Here we go:

from easy_thumbnails.files import get_thumbnailer
def copy_thumbnailer():
    obj = MyModel.objects.get(id=1)
    obj.imgB = get_thumbnailer(obj.imgA)
    obj.save()

More details about get_thumbnailer()

Adrian Lopez
  • 2,601
  • 5
  • 31
  • 48