I have this comment model that i need to get all the parent comments and their children, then prefetch it to my main queryset, this is what i got so far:
I also need to use select_related('user__profile') on each comment object.
this is my Comment model:
class AnalysisComment(TimeStampMixin):
"""
Represents comments made on Analysis.
"""
parent = models.ForeignKey(
"self", on_delete=models.CASCADE, null=True, blank=True, related_name="children"
)
uuid = models.UUIDField(
verbose_name=_("UUID"),
max_length=36,
help_text=_("Unique identifier."),
default=uuid.uuid4,
)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
verbose_name=_("User"),
on_delete=models.CASCADE,
related_name="analyses_comments",
)
text = models.TextField(_("Text"))
analysis = models.ForeignKey(
Analysis,
verbose_name=_("Analysis"),
related_name="comments",
on_delete=models.CASCADE,
)
objects = CTEManager()
now the problem is when i call the one of my parent comment children -> qs[0].parent_comments[0].children.all() then it calls queries again.
Can you help me how can i fix that?
I have this comment model that i need to get all the parent comments and their children, then prefetch it to my main queryset, this is what i got so far:
I also need to use
select_related('user__profile')
on each comment object. this is my Comment model:now the problem is when i call the one of my parent comment children ->
qs[0].parent_comments[0].children.all()
then it calls queries again. Can you help me how can i fix that?