python - django rest framework , order_by a JSON from serializers.py file -
i'm working django rest framework , want make order json how can make order_by django rest framework serializers.py file have in serializers.py
class establecimientoserializer(serializers.modelserializer): class meta: model = establecimiento depth = 1 fields = ('nombre','ciudad',) order_by = ( ('nombre',) )
i have order_by nothing json
what correct way order in json serializers.py?
i have in views.py
class establecimientoviewset(viewsets.modelviewset): queryset = establecimiento.objects.order_by('nombre') serializer_class = establecimientoserializer filter_backends = (filters.djangofilterbackend,) filter_fields = ('categoria','categoria__titulo',)
then order_by not work because have filter, how can make filter work order_by?
there's easy way, override explicitly add ordering line:
class establecimientoviewset(viewsets.modelviewset): queryset = establecimiento.objects serializer_class = establecimientoserializer filter_backends = (filters.djangofilterbackend, filters.orderingfilter) ordering = ('nombre',) #add line filter_fields = ('categoria','categoria__titulo',)
Comments
Post a Comment