【发布时间】:2021-04-10 21:25:46
【问题描述】:
我有两个表(user_type 和 raw_data),同时在列表方法中显示 raw_data user_type 需要工具来明确隐藏 raw_data 列(即 cid、eup 等)如何做到这一点?
【问题讨论】:
-
添加更多信息?像数据格式和逗号一样,这将使其他人更容易帮助您解决问题
标签: python mysql django django-rest-framework
我有两个表(user_type 和 raw_data),同时在列表方法中显示 raw_data user_type 需要工具来明确隐藏 raw_data 列(即 cid、eup 等)如何做到这一点?
【问题讨论】:
标签: python mysql django django-rest-framework
您必须像这样覆盖序列化程序的 to_representation 方法
def to_representation(self, instance):
data = {}
# Add data on the basis of user type in this dictionary
return data
【讨论】:
create 方法。您应该为此详细查看 django rest 序列化程序。否则你会卡在每一步。