0

I am using the comment library. It is built on top of django-contrib-comments

The question is, how can you make sure that when you delete a user, all comments associated with him would be deleted? I would be grateful for any help

1 Answers1

1

The Comment--(source) model defined as,

class CommentFlag(models.Model):
    user = models.ForeignKey(
        settings.AUTH_USER_MODEL, verbose_name=_('user'), related_name="comment_flags",
        on_delete=models.CASCADE,
    )
    # rest of the fields

Note that, the user field defined with a on_delete=models.CASCADE which ensures that Django emulates the behavior of the SQL constraint ON DELETE CASCADE and also deletes the object containing the ForeignKey.

Ref: models.CASCADE

JPG
  • 82,442
  • 19
  • 127
  • 206
  • Thanks for the answer, I didn't quite understand, does this mean that comments should be deleted at the moment? What changes and where do I need to make?) – new_progger_python Jan 20 '21 at 12:10