Ticket #7155: dates-qsrf-7155.diff

File dates-qsrf-7155.diff, 2.1 KB (added by jdunck, 7 years ago)

Updated patch with regression test included.

  • django/db/models/query.py

    old new  
    598598        self.query.select = []
    599599        self.query.add_date_select(self._field.column, self._kind, self._order)
    600600        if self._field.null:
    601             self.query.add_filter(('%s__isnull' % self._field.name, True))
     601            self.query.add_filter(('%s__isnull' % self._field.name, False))
    602602
    603603    def _clone(self, klass=None, setup=False, **kwargs):
    604604        c = super(DateQuerySet, self)._clone(klass, False, **kwargs)
  • tests/regressiontests/queries/models.py

    old new  
    4545class Item(models.Model):
    4646    name = models.CharField(max_length=10)
    4747    created = models.DateTimeField()
     48    modified = models.DateTimeField(blank=True, null=True)
    4849    tags = models.ManyToManyField(Tag, blank=True, null=True)
    4950    creator = models.ForeignKey(Author)
    5051    note = models.ForeignKey(Note)
     
    174175>>> time2 = datetime.datetime(2007, 12, 19, 21, 0, 0)
    175176>>> time3 = datetime.datetime(2007, 12, 20, 22, 25, 0)
    176177>>> time4 = datetime.datetime(2007, 12, 20, 21, 0, 0)
    177 >>> i1 = Item(name='one', created=time1, creator=a1, note=n3)
     178>>> i1 = Item(name='one', created=time1, modified=time1, creator=a1, note=n3)
    178179>>> i1.save()
    179180>>> i1.tags = [t1, t2]
    180181>>> i2 = Item(name='two', created=time2, creator=a2, note=n2)
     
    620621>>> Item.objects.dates('created', 'day').extra(select={'a': 1})
    621622[datetime.datetime(2007, 12, 19, 0, 0), datetime.datetime(2007, 12, 20, 0, 0)]
    622623
     624Bug #7155 -- nullable dates
     625>>> Item.objects.dates('modified', 'day')
     626[datetime.datetime(2007, 12, 19, 0, 0)]
     627
    623628Test that parallel iterators work.
    624629
    625630>>> qs = Tag.objects.all()
Back to Top