How can I place something at the top of a queryset in Django Rest Framework?

I have a model Post with field pinned_until = models.DateTimeField(blank=True, null=True). Let's say pinned_until has any value that is before the current time (timezone.now()), I want it to go at the top of the queryset, so it is first in the list of serialized response data.

How can I accomplish that? I know it has something to do with annotate, but I haven't been able to figure it out so far.

Back to Top