Serialising in wrong order

14 views
Skip to first unread message

SG

unread,
Aug 10, 2016, 12:11:30 PM8/10/16
to Django REST framework
I have two serializers set up as 

class LineChartDataSerializer(serializers.ModelSerializer):
  class Meta:
    model = LineChartData
    fields = ('date','price')
    # order_by = (('date',))
    # ordering = ['-date']

class CompanyForLineChartsSerializer(serializers.ModelSerializer):
  data = LineChartDataSerializer(many=True, source='linechartdata_set')
  class Meta:
    model = CompanyForLineCharts
    fields = ('company', 'data')


So I have tried both the ways to order the output but nothing works. Sometimes the json order gets fine(ie chronological order) but most of the times, the is not the right order, in fact it does not have any order. Data is stored in a chronological order in the database(verified that). The database I am using is Postgresql(should not be a problem I think). What is and where is wrong? Any input will be helpful. I THINK it's a drf bug. Anyway, thanks.

Xavier Ordoquy

unread,
Aug 10, 2016, 12:54:29 PM8/10/16
to django-res...@googlegroups.com
Hi,

You should apply ordering to the Django Model.

Regards,
Xavier Ordoquy,
Linovia.

--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages