So, I have a Comment model in a django project I am trying to make, what I want to do is to override the on_delete function of the ForeignKey
COMMENT_TYPES = (
(1, "Comment"),
(2, "Reply to a comment"))
class Comment(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE)
comment_text = models.CharField(max_length=80, blank=False, null=False)
id = models.UUIDField(default=uuid.uuid4, unique=True, primary_key=True,editable=False)
date_created = models.DateTimeField(auto_now_add=True)
date_edited = models.DateTimeField(auto_now=True)
post = models.ForeignKey(Post, on_delete=models.CASCADE)
parent_comment = models.ForeignKey('self', blank=True, null=True, on_delete=models.SET_NULL)
comment_type = models.IntegerField(choices=COMMENT_TYPES, default=1)
What I want is that when I delete a comment, then all the comments that were linked to the deleted comment, their comment_type should change from 2('reply to a comment') to 1('comment'), so is there a way to override the on_delete function, SET_NULL so that I can change the value in the comment_type field?