Skip to content

Instantly share code, notes, and snippets.

@sanjaykrishnan
Created April 24, 2020 05:56
Show Gist options
  • Save sanjaykrishnan/d5344e7fe69d9663fc8b1fa0b2b7bb66 to your computer and use it in GitHub Desktop.
Save sanjaykrishnan/d5344e7fe69d9663fc8b1fa0b2b7bb66 to your computer and use it in GitHub Desktop.
MP Node Ordering
qs = ProductCategory.objects.all()
slug_list = [item['slug'] for item in cat_list if item['slug'] in qs_slugs]
preserved = Case(*[When(slug=slug, then=pos) for pos, slug in enumerate(slug_list)])
qs= qs.order_by(preserved)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment