0

I have some files and info about them is in a SQL db. For a given group of files, they will all share a common gallery_id(text) and different upload_time(datetime). I'm trying to get a list of files that all share a common gallery id and then sort them by upload_time, but it isn't working. This is the syntax I used:

    >>> foo = Storedfile.query.filter_by(
        gallery_id ='kgLivY').all().order_by(Storedfile.upload_time)
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        AttributeError: 'list' object has no attribute 'order_by'

What am I doing wrong here?

1 Answer 1

8

You need to do the .all() last.

foo = Storedfile.query.filter_by(
    gallery_id='kgLivY').order_by(
        Storedfile.upload_time
    ).all()

all() returns a standard python list which then doesn't have the attribute/method order_by.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.