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())
2.1m questions
2.1m answers
60 comments
57.0k users