[Django]-Django ORM – get() with order_by()

4👍

How about

Model.objects.filter(some=condition).order_by('name').first()

2👍

get() wont take order_by() as get only returns one single object and you cannot order by one one row.

and for order by you need multiple rows for the ordering. use filter(‘your where clause’).order_by(‘asc/desc’)

hope it helps

Leave a comment