Skip to content

find_thumbnail doesn't work on ImageSubset #43

@picakoch

Description

@picakoch

I might not use the library as expected, but I could not find a way to use the find_thumbnail method on a ImageSubset object (returned by get_image_set). I get the following error :
AttributeError: 'ImageSubset' object has no attribute 'filter_by'

Looking in the code, it doesn't seem surprising since ImageSubset is not a descendant of BaseImageQuery, and the method filter_by is called on the self variable.

Could you please let me know how this should be done ?
Here is a snippet of my code (Python 3, imageattach version 1.0.0):

class EventPicture(db.Model, Image):
    __tablename__ = 'event_picture'
    event_id = db.Column(db.Integer, db.ForeignKey('event.id'), primary_key=True)
    event = db.relationship("Event")
    order_index = db.Column(db.Integer, primary_key=True)  

    @property
    def object_id(self):
        key = '{0},{1}'.format(self.event_id, self.order_index).encode('ascii')
        return int(sha1(key).hexdigest(), 16)

class Event(db.Model):
    __tablename__ = 'event'
    pictures = image_attachment('EventPicture', uselist=True)

    def get_photo(self, i, width=None, height=None):
    """ get the photo with index i and given width/height """
        with store_context(store):
            image_set = self.pictures.get_image_set(order_index=i)
            image_set.find_thumbnail(width=width,height=height) # This is where the exception occurs
           # find_thumbnail tries to execute filter_by on self, but ImageSubset is not a query, it's query is in it's query attribute.

If I reproduce the code of find_thumbnail but replacing the q variable with image_set.query, then it works smoothly.

Thanks a lot,
Best regards,
Antoine

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions