9-bits
9-bits

Reputation: 10765

Django queryset operations order

I'm trying to order a queryset and then filter the ordered set. Should this work? Or is it required that the order_by is the last operation in the chain?

for example

qs.order_by(books_count).filter(author="bob")

is this the same as?

qs.filter(author="bob").order_by(books_count)

I'm not getting the same results between the two.

Upvotes: 2

Views: 661

Answers (1)

9-bits
9-bits

Reputation: 10765

Note - as per the comments above, the order in which you apply filters (filter, order_by) does not matter.

Upvotes: 1

Related Questions