Which method is used to sort a Django QuerySet?

34. Which method is used to sort a Django QuerySet?

  1. sort()
  2. sort_by()
  3. order_by()
  4. 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.

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.