0
我使用GET與tastypie篩選結果,並需要通過datefield排序結果,但tastypie抱怨該字段不允許排序。在Django與Tastypie,無法獲得order_by與關係
Django version: 1.10.2
Tastypie version: 0.13.3
實例網址:
localhost:8000/foos/api/foos/?format=json?order_by=bars__insp_date
例Tastypie資源:
class BarResource(ModelResource):
class Meta:
queryset = Bar.objects.all().distinct()
resource_name = 'bars'
filtering = {
'insp_date': ALL_WITH_RELATIONS,
}
allowed_methods = ['get']
ordering = ['insp_date']
class FooResource(ModelResource):
onlinereports = fields.ToManyField(
BarResource,
'bars',
null=True,
full=True,
)
class Meta:
queryset = Foo.objects.all().distinct()
resource_name = 'foos'
filtering = {
'bars': ALL_WITH_RELATIONS,
}
ordering = ['bars']
響應:
{
error: "The 'bars' field does not allow ordering."
}
您是否嘗試將「bars__insp_date」添加到FooResource的排序列表中? – makaveli
@makaveli工作。謝謝! – Twitch