I'm trying to sort a query according to a foreign key field case insensitive. My models are:
class Post(models.Model):
title = models.CharField(max_length = 80)
author = models.ForeignKey(User, default = User)
trade_option = models.CharField(max_length= 10)
class Book(models.Model):
book_title = models.CharField(max_length = 60)
post = models.ForeignKey(Post)
I want to sort my post objects according to the book_title field case insensitive.
I know if I want to sort case insensitive with the fields in Class Post I can just do:
posts = Post.objects.filter(trade_option= 'buy').extra(select =
{'lower_name' : 'lower( title )'}).order_by('lower_name')
However, when I try the same technique with sorting with foreign key book with book_title:
posts = Post.objects.filter(trade_option= 'buy').extra(select =
{'lower_name' : 'lower( book__book_title )'}).order_by('lower_name')
I get the error "no such column: book__boot_title"
I would like to know where I'm doing this wrong. Thanks