我们说我有一个创建$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
对象:
Team
我有一个ModelViewSet如下:
class Team(Model):
name = CharField()
class Player(Model):
name = CharField()
team = ForeignKey(Team)
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
数据?