Skip to content

Commit

Permalink
changed replies list to descending order
Browse files Browse the repository at this point in the history
  • Loading branch information
genonfire committed Apr 21, 2024
1 parent 607df61 commit dc9a7f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
7 changes: 4 additions & 3 deletions communities/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models
from django.db.models import (
Case,
F,
IntegerField,
Q,
When,
Expand Down Expand Up @@ -220,11 +221,11 @@ def thread(self, thread, user):

replies = self.filter(thread_replies).annotate(
custom_order=Case(
When(reply_id=0, then='id'),
default='reply_id',
When(reply_id=0, then=F('id')),
default=F('reply_id'),
output_field=IntegerField(),
)
).order_by('custom_order', 'id')
).order_by('-custom_order', 'id')
return replies

def my(self, user):
Expand Down
18 changes: 9 additions & 9 deletions tests/communities/test_reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,16 @@ def test_reply_list(self):
auth=True
)
self.check(len(self.data), 5)
self.check(self.data[0].get('content'), '1')
self.check(self.data[0].get('content'), '5')
self.check(self.data[0].get('reply_id'), 0)
self.check(self.data[1].get('content'), '2')
self.check(self.data[1].get('reply_id'), reply_id)
self.check(self.data[2].get('content'), '3')
self.check(self.data[2].get('reply_id'), reply_id)
self.check(self.data[3].get('content'), '4')
self.check(self.data[3].get('reply_id'), 0)
self.check(self.data[4].get('content'), '5')
self.check(self.data[4].get('reply_id'), 0)
self.check(self.data[1].get('content'), '4')
self.check(self.data[1].get('reply_id'), 0)
self.check(self.data[2].get('content'), '1')
self.check(self.data[2].get('reply_id'), 0)
self.check(self.data[3].get('content'), '2')
self.check(self.data[3].get('reply_id'), reply_id)
self.check(self.data[4].get('content'), '3')
self.check(self.data[4].get('reply_id'), reply_id)

self.delete(
'/api/communities/r/%d/' % self.data[4].get('id'),
Expand Down

0 comments on commit dc9a7f6

Please sign in to comment.