have instances be filtered by ID in case of no filtering criteria passed in

and then switch from using order by ID as a fallback for all ordering and instead
just set instances ordering to ID as default to prevent
OrderedManyToMany fields ordering from being interrupted.
This commit is contained in:
Rebeccah 2022-03-16 17:28:23 -04:00
parent 27dc8caabd
commit 933956eccb
No known key found for this signature in database
GPG Key ID: A102D27DFFAF3552
2 changed files with 4 additions and 3 deletions

View File

@ -398,11 +398,11 @@ class OrderByBackend(BaseFilterBackend):
order_by = value.split(',')
else:
order_by = (value,)
if order_by is None:
order_by = self.get_default_ordering(view)
default_order_by = self.get_default_ordering(view)
# glue the order by and default order by together so that the default is the backup option
order_by = list(order_by or []) + list(default_order_by or [])
if order_by:
order_by = self._validate_ordering_fields(queryset.model, order_by)
# Special handling of the type field for ordering. In this
# case, we're not sorting exactly on the type field, but
# given the limited number of views with multiple types,

View File

@ -365,6 +365,7 @@ class InstanceList(ListAPIView):
model = models.Instance
serializer_class = serializers.InstanceSerializer
search_fields = ('hostname',)
ordering = ('id',)
class InstanceDetail(RetrieveUpdateAPIView):