def to_representation(self, instance):
'''
This method is overridden to remove blank fields from serialized output. We could put this into a subclassed
ModelSerializer if we want it to apply to all our Serializers.
:param instance:
:return:
'''
rep = super().to_representation(instance)
return {key: val for key, val in rep.items() if val}
评论列表
文章目录