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