Skip to content

Instantly share code, notes, and snippets.

@paltman
Created October 6, 2017 04:45
Show Gist options
  • Save paltman/c0f96cf47c3a92576aa9f3447782cd06 to your computer and use it in GitHub Desktop.
Save paltman/c0f96cf47c3a92576aa9f3447782cd06 to your computer and use it in GitHub Desktop.
@property
def notes(self):
order_by = "pk"
if self.note_order:
pks = self.note_order.split("|")
order_by = models.Case(*[
models.When(pk=pk, then=pos)
for pos, pk in enumerate(pks)
])
return self.note_set.all().order_by(order_by)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment