MyModel:
name = models.CharField(max_length=255)
I try to sort the queryset. I just think about this:
obj = MyModel.objects.all().sort_by(-len(name)) #???
Any idea?
The new hotness (as of Django 1.8 or so) is Length()
from django.db.models.functions import Length obj = MyModel.objects.all().order_by(Length('name').asc())
1.4m articles
1.4m replys
5 comments
57.0k users