0
可能是这样一个重复: Copy data to and from the same table and change the value of copied data in one column to a specified value复制数据,并从同一个表,并在Django在一列更改复制的数据值指定的值
我要复制的数据单表并粘贴在同一个表从给定的模型改变owner
coloumn:
class Task(models.Model):
description = models.CharField(max_length=128)
owner = models.ForeignKey(User)
category = models.ForeignKey(Category)
什么Django的方式做到这一点?
这不会更新相同的数据吗?我想要的是: 'a = Task.objects.filter(user = 1)'#获取admin创建的数据 复制'a'的所有数据并更新'user = request.user.id' – pynovice
@ user2032220 ,你在壳上试过了吗?否,它将创建新行,因为'.pk'设置为'None'。 – Rohan
是的,就像一个魅力。您已将任务实例的'pk'分配给'None'。你能解释一下代码吗? +1已经。 – pynovice