Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

314
Vistas
Rename RelatedField ordering filter in django rest framework

In a django rest framework APIView we specify ordering fields using the same method as the search filters and therefore we can specify ordering using related names.

ordering_fields = ('username', 'email', 'profile__profession')

The route would look like this: https://example.com/route?ordering=profile__profession

However we would rather avoid to display the relation between the models in the api and then specify profession instead of profile__profession. Such as https://example.com/route?ordering=profession

Can this be achieved without having to implement the sorting in the APIView's def get_queryset(self):?

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

It can be achieved with a minor change in def get_queryset(self).

def get_queryset(self):
    query = super(UserListView, self).get_queryset().annotate(profession=F('profile__profession'))
    return query
about 4 years ago · Santiago Trujillo Denunciar

0

You will need to write your own OrderingFilter based on the Django REST framework one by overriding get_ordering and using a dictionary to map the "short name" to the full queryset string.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda