Corregimos datepart
This commit is contained in:
@@ -129,10 +129,10 @@ class Q(QMixin):
|
|||||||
|
|
||||||
if lookup in ['year', 'month', 'day' 'hour', 'minute', 'second']:
|
if lookup in ['year', 'month', 'day' 'hour', 'minute', 'second']:
|
||||||
if arr:
|
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)
|
return self._process(column, value)
|
||||||
else:
|
else:
|
||||||
return "DATEPART('{0}')={1}".format(lookup, value)
|
return "DATEPART('{0}', {1})={2}".format(lookup, column, value)
|
||||||
|
|
||||||
if lookup in self.op_map.keys():
|
if lookup in self.op_map.keys():
|
||||||
return "{0}{1}{2}".format(column, self.op_map[lookup], self._get_value(value))
|
return "{0}{1}{2}".format(column, self.op_map[lookup], self._get_value(value))
|
||||||
|
|||||||
3
tests.py
3
tests.py
@@ -19,6 +19,9 @@ class TestSqlBuilder(unittest.TestCase):
|
|||||||
date = datetime.datetime(2010, 1, 15, 23, 59, 38)
|
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=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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user