I have these models:
class Project(models.Model):
title=models.CharField(max_length=80)date_created=models.DateTimeField(auto_now_add=True)e)
category = models.ForeignKey(Category)
class Category(models.Model):
name = models.CharField(max_length=80)
And this in views:
cat_list = Category.objects.order_by(order_by)
for c in cat_list:
count = Project.objects.filter(category__id=c.id).count()
setattr(c, 'count', count)
How can I now order this by COUNT attribute?