【发布时间】:2017-06-07 16:29:00
【问题描述】:
我有两个序列化程序,其中一个以many=True 关系引用另一个。
class AttributeInParentSerializer(ModelSerializer):
masterdata_type = CharField(max_length=256, source='masterdata_type_id')
class Meta:
model = Attribute
fields = ('uuid', 'masterdata_type')
class ArticleInArticleSetSerializer(ModelSerializer):
attributes = AttributeInParentSerializer(many=True)
class Meta:
model = Article
fields = ('uuid', 'attributes')
文章中属性的顺序并不总是相同的,但我想以相同的顺序输出它们,所以在这种情况下对字段masterdata_type进行排序。我怎样才能做到这一点?请注意,如果可能,我不想更改序列化程序的任何客户端,当然也不想更改任何模型。
【问题讨论】:
标签: django sorting django-rest-framework serialization