python - Trouble with loading a tree structure in django models -
i have 2 django models this
class thread(models.model): title = models.charfield(max_length=255, blank=true) class post(models.model): message = models.textfield(blank=true) thread = models.foreignkey(thread, related_name='posts') depth = models.positiveintegerfield(default=0) reply_to = models.foreignkey('self', null=true, related_name='replies', blank=true)
i noticed when this
roots = thread.posts.filter(depth=0) post in roots: replies = post.replies
django execute query roots executes new queries children of specific post, know working posts in specific thread.
i want know if there way make django load posts 1 query , use model's relation children recursively.
it's not built-in django, can use apps treebeard or django-mptt this.
Comments
Post a Comment