【问题标题】:Not show ids in django response [duplicate]在 django 响应中不显示 ID [重复]
【发布时间】:2020-05-17 06:51:37
【问题描述】:

大家好,我正在使用 rest-freamework 创建一些 API,作为响应,我不想在外国字段中显示 id。

{
    "id": 1,
    "name": "My Team",
    "description": "This is my team",
    "dealership": 1,
    "users": [
        6,
        9,
    ]
}

在改变中,我想要类似的东西:

{
    "id": 1,
    "name": "My Team",
    "description": "This is my team",
    "dealership": "Chevrolet Miami",
    "users": [
        "Jack Black",
        "Brad Pitt"
    ]
}

【问题讨论】:

  • 请也写下你的序列化器文件的代码。

标签: django django-rest-framework serialization


【解决方案1】:

Gilbeesh,序列化代码为:

class TeamSerializer(serializers.ModelSerializer):

    class Meta:
        model = Teams
        fields = ["id", "name", "description", "dealership", "users"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    • 2018-02-10
    • 1970-01-01
    • 2018-11-10
    • 1970-01-01
    • 2013-09-20
    • 1970-01-01
    相关资源
    最近更新 更多