Corregimos datepart

This commit is contained in:
2014-11-24 23:22:53 +01:00
parent 2e8de67b23
commit 11d2b1a10a
2 changed files with 5 additions and 2 deletions

View File

@@ -129,10 +129,10 @@ class Q(QMixin):
if lookup in ['year', 'month', 'day' 'hour', 'minute', 'second']:
if arr:
column = "DATEPART('{0}')__{1}".format(lookup, arr.pop(0))
column = "DATEPART('{0}', {1})__{2}".format(lookup, column, arr.pop(0))
return self._process(column, value)
else:
return "DATEPART('{0}')={1}".format(lookup, value)
return "DATEPART('{0}', {1})={2}".format(lookup, column, value)
if lookup in self.op_map.keys():
return "{0}{1}{2}".format(column, self.op_map[lookup], self._get_value(value))

View File

@@ -19,6 +19,9 @@ class TestSqlBuilder(unittest.TestCase):
date = datetime.datetime(2010, 1, 15, 23, 59, 38)
self.assertEqual(str(Q(fecha=date)), "(fecha='2010-01-15 23:59:38')")
self.assertEqual(str(Q(fecha__year__lte=2012)), "(DATEPART('year', fecha)<=2012)")
self.assertEqual(str(Q(fecha__year=2012)), "(DATEPART('year', fecha)=2012)")
if __name__ == '__main__':
unittest.main()