docs: def _order_by_pks(qs, pks):
      """
      Adjust the given queryset to order items according to the explicit ordering
      of PKs provided.
  
      This is a PostgreSQL-specific DB hack, based on:
      blog.mathieu-leplatre.info/django-create-a-queryset-from-a-list-preserving-order.html
      """
      pk_colname = '%s.%s' % (
          qs.model._meta.db_table, qs.model._meta.pk.column)
      clauses = ' '.join(
          ['WHEN %s=%s THEN %s' % (pk_colname, pk, i)
              for i, pk in enumerate(pks)]
      )
      ordering = 'CASE %s END' % clauses
      return qs.extra(
          select={'pk_ordering': ordering}, order_by=('pk_ordering',))