3

I'm trying to use the dehydrate method to generate my thumbnail like so:

class PostResource(ModelResource):
    user = fields.ForeignKey(UserResource, 'user')

    class Meta:
        queryset = Post.objects.all()
        resource_name = 'post'
        authentication = Authentication()
        authorization = DjangoAuthorization()
        filtering = {
            'published': ALL,
            'type': ALL,
        }
        ordering = [
            'hot_score',
            'likes',
            'date_created',
        ]

    def dehydrate(self, bundle):
        bundle.data['thumb'] = get_thumbnailer(self.image1, "image.jpg").get_thumbnail({'size': (95, 95),}).url
        return bundle

What I get back is this error: "'FileField' object has no attribute 'closed'"

Am I getting this because self.image1 isn't a "real" FileField object (its a tastypie.fields.FileField which doesn't seem to be based off Django's FileField) so it doesn't have all the usual methods that easy-thumbnails needs? And if so, is there a solution?

If the solution is to use sorl-thumbnail instead, I will understand :) Thank you for any help provided!

yprez
  • 14,854
  • 11
  • 55
  • 70
renegadeofunk
  • 445
  • 1
  • 3
  • 11

1 Answers1

2

Converted comment:

Get the image from the Django model rather than from the resource:

get_thumbnailer(bundle.obj.image1, "image.jpg").get_thumbnail({'size': (95, 95),}).url
dokkaebi
  • 9,004
  • 3
  • 42
  • 60