82👍
✅
No, you can’t do that. order_by
is applied at the database level, but the database can’t know anything about your custom Python methods.
You can either use the separate fields to order:
Author.objects.order_by('first_name', 'last_name')
or do the ordering in Python:
sorted(Author.objects.all(), key=lambda a: a.full_name)
Source:stackexchange.com