我想按顺序订购,entry_count
但似乎(来自 django 错误)我只能按名称和状态订购。entry_count
在此示例中如何订购?谢谢
Category.objects.filter(status='Published').order_by('-entry_count')
模型.py
class Category(models.Model):
"""
Entry Categories.
"""
name = models.CharField(max_length=60, help_text="Title of Category")
status = models.CharField(max_length=16, choices=STATUS_CHOICES,
default="Draft", )
@property
def entry_count(self):
return Entry.objects.filter(category=self.id).count()