Django

Code

Changeset 7763

Show
Ignore:
Timestamp:
06/26/08 02:51:19 (5 months ago)
Author:
mtredinnick
Message:

Fixed #7105 -- Fixed dates() queries in light of model inheritance.

Files:

Legend:

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

    r7742 r7763  
    689689        self.query = self.query.clone(klass=sql.DateQuery, setup=True) 
    690690        self.query.select = [] 
    691         self.query.add_date_select(self._field.column, self._kind, self._order) 
     691        self.query.add_date_select(self._field, self._kind, self._order) 
    692692        if self._field.null: 
    693693            self.query.add_filter(('%s__isnull' % self._field.name, False)) 
  • django/trunk/django/db/models/sql/subqueries.py

    r7635 r7763  
    358358                yield date 
    359359 
    360     def add_date_select(self, column, lookup_type, order='ASC'): 
     360    def add_date_select(self, field, lookup_type, order='ASC'): 
    361361        """ 
    362362        Converts the query into a date extraction query. 
    363363        """ 
    364         alias = self.join((None, self.model._meta.db_table, None, None)) 
    365         select = Date((alias, column), lookup_type, 
     364        result = self.setup_joins([field.name], self.get_meta(), 
     365                self.get_initial_alias(), False) 
     366        alias = result[3][-1] 
     367        select = Date((alias, field.column), lookup_type, 
    366368                self.connection.ops.date_trunc_sql) 
    367369        self.select = [select] 
  • django/trunk/tests/regressiontests/model_inheritance_regress/models.py

    r7600 r7763  
    22Regression tests for Model inheritance behaviour. 
    33""" 
     4 
     5import datetime 
    46 
    57from django.db import models 
     
    1113    class Meta: 
    1214        ordering = ('name',) 
    13          
     15 
    1416    def __unicode__(self): 
    1517        return u"%s the place" % self.name 
     
    3638        return u"%s the parking lot" % self.name 
    3739 
     40class Parent(models.Model): 
     41    created = models.DateTimeField(default=datetime.datetime.now) 
     42 
     43class Child(Parent): 
     44    name = models.CharField(max_length=10) 
     45 
    3846__test__ = {'API_TESTS':""" 
    3947# Regression for #7350, #7202 
    40 # Check that when you create a Parent object with a specific reference to an existent 
    41 # child instance, saving the Parent doesn't duplicate the child.  
    42 # This behaviour is only activated during a raw save - it is mostly relevant to  
     48# Check that when you create a Parent object with a specific reference to an 
     49# existent child instance, saving the Parent doesn't duplicate the child. This 
     50# behaviour is only activated during a raw save - it is mostly relevant to 
    4351# deserialization, but any sort of CORBA style 'narrow()' API would require a 
    4452# similar approach. 
     
    118126[[('name', u"Guido's All New House of Pasta"), ('serves_gnocchi', False), ('serves_hot_dogs', False)]] 
    119127 
     128# Regressions tests for #7105: dates() queries should be able to use fields 
     129# from the parent model as easily as the child. 
     130>>> obj = Child.objects.create(name='child', created=datetime.datetime(2008, 6, 26, 17, 0, 0)) 
     131>>> Child.objects.dates('created', 'month') 
     132[datetime.datetime(2008, 6, 1, 0, 0)] 
     133 
    120134"""}