Home »
Python »
Django MCQs
Which method is used to sort a Django QuerySet?
34. Which method is used to sort a Django QuerySet?
- sort()
- sort_by()
- order_by()
- order()
Answer: C) order_by()
Explanation:
The order_by() method is used to sort a Django QuerySet. Consider the below code statement –
dataObj = students.objects.all().order_by('name').values()
Where, "students" is the model name, and "name" is the column name. The above statement will sort the QuerySet based on the names.