排序
All checks were successful
Deploy to Server / deploy (push) Successful in 24s

This commit is contained in:
jeremygan2021
2026-02-25 00:53:01 +08:00
parent 05299060dc
commit 8298eb6add
2 changed files with 9 additions and 8 deletions

View File

@@ -145,8 +145,9 @@ class Topic(models.Model):
is_new = self.pk is None
super().save(*args, **kwargs)
if is_new and getattr(self, 'order', 0) == 0:
Topic.objects.filter(pk=self.pk).update(order=self.pk)
self.order = self.pk
# 默认使用 -id 作为排序值确保新帖子默认排在前面order越小越靠前
Topic.objects.filter(pk=self.pk).update(order=-self.pk)
self.order = -self.pk
def __str__(self):
return self.title