I intend to subclass the ThumbnailBackend
class from sorl.thumbnail.base
. What I need to do is to override the _get_thumbnail_filename
method, to add some stuff to the filename generated by the original (parent) method. To do so, I wrote something like this:
from sorl.thumbnail.base import ThumbnailBackend
class MyThumbnailBackend(ThumbnailBackend):
def _get_thumbnail_filename(self, source, geometry_string, options):
oldpath = super(ThumbnailBackend,self)._get_thumbnail_filename(source, geometry_string, options)
oldpathlist = oldpath.split('/')
# get the last item of 'oldpathlist' and
# sufix it with useful info...
# join the items with the modified one...
return newpath
There should be something I'm missing with python inheritance, because I keep getting the following error:
AttributeError at /location/of/the/caller/class/
'super' object has no attribute '_get_thumbnail_filename'
If I'm right, I'm importing this class, in the first line: from sorl.thumbnail.base import ThumbnailBackend
which definitely has a _get_thumbnail_filename
method.
What am I doing wrong?
Thank you very much!
You have to call super with the current class, change super(ThumbnailBackend, self)
to super(MyThumbnailBackend, self)
, like this
class MyThumbnailBackend(ThumbnailBackend):
def _get_thumbnail_filename(self, source, geometry_string, options):
return super(MyThumbnailBackend, self)._get_thumbnail_filename(source, geometry_string, options)