364 | | order_field = self.get_ordering_field(field_name) |
365 | | if not order_field: |
366 | | continue # No 'admin_order_field', skip it |
367 | | if isinstance(order_field, OrderBy): |
368 | | if pfx == "-": |
369 | | order_field = order_field.copy() |
370 | | order_field.reverse_ordering() |
371 | | ordering.append(order_field) |
372 | | elif hasattr(order_field, "resolve_expression"): |
373 | | # order_field is an expression. |
374 | | ordering.append( |
375 | | order_field.desc() if pfx == "-" else order_field.asc() |
376 | | ) |
377 | | # reverse order if order_field has already "-" as prefix |
378 | | elif order_field.startswith("-") and pfx == "-": |
379 | | ordering.append(order_field[1:]) |
380 | | else: |
381 | | ordering.append(pfx + order_field) |
| 364 | order_fields = self.get_ordering_fields(field_name) |
| 365 | if not isinstance(order_fields, (list, tuple)): |
| 366 | order_fields = (order_fields,) |
| 367 | for order_field in order_fields: |
| 368 | if not order_field: |
| 369 | continue # No 'admin_order_field', skip it |
| 370 | if isinstance(order_field, OrderBy): |
| 371 | if pfx == "-": |
| 372 | order_field = order_field.copy() |
| 373 | order_field.reverse_ordering() |
| 374 | ordering.append(order_field) |
| 375 | elif hasattr(order_field, "resolve_expression"): |
| 376 | # order_field is an expression. |
| 377 | ordering.append( |
| 378 | order_field.desc() if pfx == "-" else order_field.asc() |
| 379 | ) |
| 380 | # reverse order if order_field has already "-" as prefix |
| 381 | elif order_field.startswith("-") and pfx == "-": |
| 382 | ordering.append(order_field[1:]) |
| 383 | else: |
| 384 | ordering.append(pfx + order_field) |