Ticket #7302: 7302.1.diff

File 7302.1.diff, 1.2 KB (added by Ivan Sagalaev, 16 years ago)

Possible fix with tests

  • django/db/models/sql/query.py

     
    629629                    result.append('%s %s' % (elt, order))
    630630            else:
    631631                col, order = get_order_dir(field, asc)
    632                 elt = qn(col)
     632                elt = qn2(col)
    633633                if distinct and elt not in select_aliases:
    634634                    ordering_aliases.append(elt)
    635635                result.append('%s %s' % (elt, order))
  • tests/modeltests/ordering/models.py

     
    7777# take the first two).
    7878>>> Article.objects.all().reverse()[:2]
    7979[<Article: Article 1>, <Article: Article 3>]
     80
     81# Ordering with 'extra' properly quotes aliases to not clash with SQL keywords
     82>>> Article.objects.extra(select={'order': 'pub_date'}, order_by=['order', 'headline'])
     83[<Article: Article 1>, <Article: Article 2>, <Article: Article 3>, <Article: Article 4>]
    8084"""}
Back to Top