如何使Django Rest Framework可浏览API显示模型中的所有字段?

时间:2019-01-21 16:50:47

标签: python django-rest-framework

我试图将DRF模型中的所有字段都显示在可浏览的API页面中。我没有显示全部,而是从模型中仅获得了7个明显随机的字段。

我尝试将排序添加到模型类。我尝试将序列化器字段从写出的列表更改为全部。

models.py

select count(TypeTrasp) as nr, 
[DataAttesa KPI2-1] as Data FROM [db_Out$] 
Where TypeTrasp = 'AOG' and [DGR]= 'Out of Time' group by [DataAttesa KPI2-1]`

serializers.py

class OfferingExtended(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    field2 = models.FloatField
    field3 = models.FloatField
    field4 = models.IntegerField
    field5 = models.FloatField
    field6 = models.CharField(max_length=32)
    field7 = models.FloatField
    field8 = models.CharField(max_length=32)
    field9 = models.IntegerField
    field10 = models.FloatField

    class Meta:
        ordering = ['-id']

views.py

class OfferingSerializer(serializers.ModelSerializer):
    class Meta:
        model = OfferingExtended
        fields = '__all__'

当我浏览到http://127.0.0.1:8000/Offering/时,我希望能看到所有10个字段,但是我看到的7个字段的顺序不是特别明显。

如何强制DRF以模型中表示的顺序显示所有可用字段?

0 个答案:

没有答案