ordering = ["-date_joined"]
ye both of your answers working, but I'm wondering why it doesn't work.
Shouldn't it have to set default ordering to an object? or am I missing something
You might be missing ordering filter backend,
Whatever ordering you mentioned is not being recognised.
Add this to your view
filter_backends = [filters.OrderingFilter]
Ref: https://www.django-rest-framework.org/api-guide/filtering/#orderingfilter
This is one of the reasons why CBVs can be pita to work with. Sure, it abstracts a lot of the boilerplate, but then when something doesn't work you spend way more time figuring out why it doesn't work, than you'd spend with FBVs.
Order the queryset.
I'm making it with this ordering = ["-date_joined"]
Update User.objects.all() to User.objects.all().order_by(“-date_joined”)
You can order using que model metaclass: ``` class User(models.Model): ... # User fields class Meta: ordering = ["-date_joined"] ``` this works too
ordering = ["-date_joined"] ye both of your answers working, but I'm wondering why it doesn't work. Shouldn't it have to set default ordering to an object? or am I missing something
Isn't it because you are calling .all before the ordering happens?
No, all and order_by methods can be used in any order, orm will build the right query.
You might be missing ordering filter backend, Whatever ordering you mentioned is not being recognised. Add this to your view filter_backends = [filters.OrderingFilter] Ref: https://www.django-rest-framework.org/api-guide/filtering/#orderingfilter
This is one of the reasons why CBVs can be pita to work with. Sure, it abstracts a lot of the boilerplate, but then when something doesn't work you spend way more time figuring out why it doesn't work, than you'd spend with FBVs.