Show More
@@ -282,6 +282,7 b' class Thread(models.Model):' | |||||
282 | def get_reply_tree(self): |
|
282 | def get_reply_tree(self): | |
283 | replies = self.get_replies().prefetch_related('refposts') |
|
283 | replies = self.get_replies().prefetch_related('refposts') | |
284 | tree = [] |
|
284 | tree = [] | |
|
285 | parent_positions = {} | |||
285 | for reply in replies: |
|
286 | for reply in replies: | |
286 | parents = reply.refposts.all() |
|
287 | parents = reply.refposts.all() | |
287 | found_parent = False |
|
288 | found_parent = False | |
@@ -290,8 +291,11 b' class Thread(models.Model):' | |||||
290 | for depth, element in tree: |
|
291 | for depth, element in tree: | |
291 | index += 1 |
|
292 | index += 1 | |
292 | if element in parents: |
|
293 | if element in parents: | |
293 | tree.insert(index, (depth + 1, reply)) |
|
294 | offset_under_parent = parent_positions.get(element, 1) | |
|
295 | tree.insert(index + offset_under_parent - 1, (depth + 1, reply)) | |||
|
296 | parent_positions[element] = offset_under_parent + 1 | |||
294 | found_parent = True |
|
297 | found_parent = True | |
|
298 | ||||
295 | if not found_parent: |
|
299 | if not found_parent: | |
296 | tree.append((0, reply)) |
|
300 | tree.append((0, reply)) | |
297 |
|
301 |
General Comments 0
You need to be logged in to leave comments.
Login now