If there exists an old data of a model say ,
query=Emp.objects.filter(pk=profile.id)
Is there a easier way to copy the same values into the same model again..
Now that the id will be different so..
I have this requirement.
Thanks..
If there exists an old data of a model say ,
query=Emp.objects.filter(pk=profile.id)
Is there a easier way to copy the same values into the same model again..
Now that the id will be different so..
I have this requirement.
Thanks..
Unless you have a complex model with inheritance, this should work:
query.pk = None
query.save() #Will insert new record
For the other case I found a snippet here, did not test it however.
object = Emp.objects.get(pk=profile.id)
object.save(force_insert=True)
It's much more explicit then removing primary key's value. See also "forcing an insert or update" in Django documentation.