code: def remove_invalid_fields(self, queryset, fields, view):
          
  
          valid_orderings = []
          invalid_orderings = []
  
          # for each field sent down from the query param,
          # determine if its valid or invalid
          for term in fields:
              stripped_term = term.lstrip('-')
              # add back the '-' add the end if necessary
              reverse_sort_term = '' if len(stripped_term) is len(term) else '-'
              ordering = self.ordering_for(stripped_term, view)
  
              if ordering:
                  valid_orderings.append(reverse_sort_term + ordering)
              else:
                  invalid_orderings.append(term)
  
          return valid_orderings, invalid_orderings
docs: Remove invalid fields from an ordering.
  
          Overwrites the DRF default remove_invalid_fields method to return
          both the valid orderings and any invalid orderings.