0

您好,我从表信息中有这些条目:

|name| city| birthplace|client|
|peter| los angeles| new york|yes|
|william| chicago| denver|yes|

我想做这样的事情:

|name| city| birthplace|client|
|peter| los angeles| new york|yes|
|william| chicago| denver|yes|
|peter| los angeles| new york|no|
|william| chicago| denver|no|

也就是说,我想添加相同的行,但对于列客户端,为新行设置 no。如何使用 Django 做到这一点?

这是我的第一行:

info = informations.objects.filter(client='yes')

最后一行返回这 2 个条目。

非常感谢 !

4

1 回答 1

0

你可以尝试这样的事情:

infoObjects = informations.objects.filter(client='yes')
for info in infoObjects:
    newObj = info
    newObj.pk = None
    newObj.client = "no"
    newObj.save()
于 2019-10-14T16:56:47.700 回答