How to prefetch comments in django [duplicate]

class Comment(models.Model):
parent_comment=models.ForeignKey(
    to='self',
    related_name='_comments',
    on_delete=models.DO_NOTHING,
    null=True,
    blank=True,

how to prefetch _comments: child_comment The deeper the depth, the deeper the N+1 query problem

Back to Top