Reputation: 3749
How do I copy the data from one record to another? That is, I have the record
pk: 1,
name: "Regis"
total: "1000.00"
I wanted to create a new exactly the same record.
pk: 2,
name: "Regis"
total: "1000.00"
Upvotes: 0
Views: 101
Reputation: 45575
Just set pk
to None
and save the record:
obj = MyModel.objects.get(pk=1)
obj.pk = None
obj.save()
This is an official method of copying model instances.
Upvotes: 3