有没有办法使用Django Rest Swagger记录POST请求中所需对象的组成?

时间:2017-05-13 14:19:43

标签: django django-rest-framework django-rest-swagger

我们说我有一个创建$res=mysqli_query($dbh, "SELECT column_b FROM table_b"); while ($r=mysqli_fetch_assoc($res)) { $ins="INSERT INTO table_a(column_a) VALUES (" . multi($r['column_b']) , ");"; if (!mysqli_query($dbh, $ins)) { die mysqli_error($dbh); } } 的端点需要一个Player对象:

models.py

Team

我有一个ModelViewSet如下:

views.py

class Team(Model):
    name = CharField()

class Player(Model):
    name = CharField()
    team = ForeignKey(Team)

serializers.py

class PlayerViewSet(ModelViewSet):
    model = Player
    serializer = PlayerSerializer

当我看到我的Django Rest Swagger时,"示例值"对于数据,我需要class TeamSerializer(ModelSerializer): class Meta: model = Team fields = "__all__" class PlayerSerializer(ModelSerializer): class Meta: model = Player fields = "__all__" 来创建一个玩家:

POST

我希望扩展{ "name": "string", "team": {} } ,以表明我需要提供{}对象来创建{"name": "string"}对象。我尝试过添加

Team

team = TeamSerializer(help_text="{'name': 'string'}"),但只将数据添加到Django Rest Swagger上的PlayerSerializer标签中。有没有办法自动将此文档添加到Model标签,Example显示所需的Model数据?

0 个答案:

没有答案