Skip to content

Instantly share code, notes, and snippets.

@carvalhochris
Last active February 27, 2023 14:34
Show Gist options
  • Select an option

  • Save carvalhochris/bb06b1ed5f882287845bab824bf94757 to your computer and use it in GitHub Desktop.

Select an option

Save carvalhochris/bb06b1ed5f882287845bab824bf94757 to your computer and use it in GitHub Desktop.
Django Rest Viewset sort by pinned, then by year
class WorkViewSet(viewsets.ModelViewSet):
queryset = Work.objects.all()
serializer_class = WorkSerializer
def get_queryset(self):
queryset = Work.objects.order_by('-pinned', '-year')
return queryset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment