i need create function to copy object of my model my code:
class Author(models.Model):
name = models.CharField(max_length=50)
class BlogPost(models.Model):
title = models.CharField(max_length=250)
body = models.CharField(max_length=None)
author = models.ForeignKey(Author ,on_delete=models.CASCADE)
data_created = models.DateTimeField(auto_now_add=datetime.now)
def copy(self):
new_post = BlogPost.objects.get(id=self.id).update(data_created=datetime.now)
new_post.save()
return new_post.id
class Comment(models.Model):
blog_post = models.ForeignKey(BlogPost , on_delete=models.CASCADE)
text = models.CharField(max_length=500)
def copy in BlogPost class for copy obejcts and create new object and update data_created to now Which after that i have 2 objects but dosent work what can i do?