I want to create a method that copies an object of the BlogPost model. my models looks like this:
class BlogPost(models.Model):
title = models.CharField(max_length=250)
body = models.TextField()
author = models.ForeignKey(Author, on_delete=models.CASCADE)
date_created = models.DateTimeField(auto_now_add=True)
def copy(self):
pass
class Comment(models.Model):
blog_post = models.ForeignKey(
BlogPost, on_delete=models.CASCADE, related_name="comments"
)
text = models.CharField(max_length=500)
my challenge is implementing the copy method. The copy method should copy the current object with all the comments related to that and I don't have any idea how to do it.