[Answered ]-Copy a model instance and update a filed in new copy

1👍

Intuition

You want to update the date_created of new copied blog post to timezone.now(), instead of date_created of old blog post time, am I right?

I guess the reason of it’s not updated, is because when you do blog.pk = None, the blog.date_created is still existed, so even you do blog.save(), blog.date_created is still old value.

Solution

blog.pk = None
blog.date_created = timezone.now() # Update the date_created to the current time
blog.save()

Leave a comment