6 examples of 'django order by desc' in Python

Every line of 'django order by desc' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
810def test_order_by(self):
811 """Ensure that order_by() propagates to QuerySets and iteration."""
812 # Order by author and ensure it takes.
813 with self.assertNumQueries(0):
814 qss = self.all.order_by('title')
815
816 # Check the titles are properly ordered.
817 with self.assertNumQueries(2):
818 data = [it.title for it in qss]
819 self.assertEqual(data, sorted(self.TITLES_BY_PK))
793def order_by(self, *args):
794 """ Order the query by the given fields.
795
796 Parameters
797 ----------
798 args: List[str or column]
799 Fields to order by. A "-" prefix denotes decending.
800
801 Returns
802 -------
803 query: SQLQuerySet
804 A clone of this queryset with the ordering terms added.
805
806 """
807 order_clauses = self.order_clauses[:]
808 related_clauses = self.related_clauses[:]
809 model = self.proxy.model
810 for arg in args:
811 if isinstance(arg, str):
812 # Convert django-style to sqlalchemy ordering column
813 if arg[0] == '-':
814 field = arg[1:]
815 ascending = False
816 else:
817 field = arg
818 ascending = True
819
820 col = resolve_member_column(model, field, related_clauses)
821
822 if ascending:
823 clause = col.asc()
824 else:
825 clause = col.desc()
826 else:
827 clause = arg
828 if clause not in order_clauses:
829 order_clauses.append(clause)
830 return self.clone(order_clauses=order_clauses,
831 related_clauses=related_clauses)
15def _get_order_field_name(self):
16 return self.model.order_field_name
76def index_order(self, obj):
77 """Content for the `index_order` column"""
78 return mark_safe(
79 '<div>Drag</div>'
80 )
458def order(self, QuerySet, is_descending):
459 QuerySet = QuerySet.order_by(('-' if is_descending else '')
460 + 'sort_name', 'year_began')
461 return (QuerySet, True)
208def sortables_ordered(self, queryset):
209 """
210 Should return a queryset that orders the objects properly
211 (e.g. for nested categories the queryset should return:
212 Parent1, Paren1Child1, Parent1Child2, Parent2, Parent2Child1 etc)
213 """
214 return queryset

Related snippets