Django

Code

Changeset 7502

Show
Ignore:
Timestamp:
04/28/08 16:15:05 (3 months ago)
Author:
adrian
Message:

Changed Query.get_columns() to quote the 'AS' column names in an extra_select situation, to match pre-queryset-refactor behavior. Added unit tests that verify this and provide an example

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/sql/query.py

    r7499 r7502  
    395395        """ 
    396396        qn = self.quote_name_unless_alias 
    397         result = ['(%s) AS %s' % (col, alias) for alias, col in self.extra_select.iteritems()] 
     397        qn2 = self.connection.ops.quote_name 
     398        result = ['(%s) AS %s' % (col, qn2(alias)) for alias, col in self.extra_select.iteritems()] 
    398399        aliases = set(self.extra_select.keys()) 
    399400        if with_aliases: 
  • django/trunk/tests/modeltests/basic/models.py

    r7477 r7502  
    399399>>> Article.objects.get(headline='Article 11') in s 
    400400True 
     401 
     402# The 'select' argument to extra() supports names with dashes in them, as long 
     403# as you use values(). 
     404>>> Article.objects.filter(pub_date__year=2008).extra(select={'dashed-value': '1'}).values('headline', 'dashed-value') 
     405[{'headline': u'Article 11', 'dashed-value': 1}, {'headline': u'Article 12', 'dashed-value': 1}] 
     406 
     407# If you use 'select' with extra() and names containing dashes on a query 
     408# that's *not* a values() query, those extra 'select' values will silently be 
     409# ignored. 
     410>>> articles = Article.objects.filter(pub_date__year=2008).extra(select={'dashed-value': '1', 'undashedvalue': '2'}) 
     411>>> articles[0].undashedvalue 
     4122 
    401413"""