django rest framework queryset doesn’t order

If your model does have an ordering it really will be reflected in the list view by default. I’d suggest overriding get_queryset() and debugging the return result there, or else explicitly adding the ordering to the queryset.

For example:

queryset = Invoice.objects.all().order_by('-published_date')

Wondering if it’s possible you’ve configured a filter that’s overriding the ordering. Worth testing what happens if you turn all filters off. I see you have the filter_fields attribute set, so assuming you’ve got something like this in your settings…

REST_FRAMEWORK = {
    'DEFAULT_FILTER_BACKENDS': ('rest_framework.filters.DjangoFilterBackend',)
}

If you comment that out does that fix things?

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)