I have one of the below example model
class Title(models.Model):
name = models.CharField(max_length=200)
provider_name = models.CharField(max_length=255, blank=True)
keywords = models.CharField(max_length=200, null=True, blank=True)
def __unicode__(self):
return '{0} - {1} (name/provider)'.format(name, provider_name)
so in order to order_by
the Title model queryset with any model field, we can just do
titles = Title.objects.all().order_by('name')
But is it possible to order_by the queryset with particular value ? i mean i want to order_by the Title model queryset with the return value of unicode
method, i.e., the combination of name and provider_name
('{0} - {1} (name/provider)'.format(name, provider_name))
So overall instead of doing order_by with Model fields/database columns, i want to order by a value(Return value of unicode method in this case)
Is that possible to order_by the queryset with a value in ORM or else we need to write raw sql in order to achieve this ?