Ejemplo n.º 1
0
 def get_db_prep_save(self, value, connection):
     if value is None:
         return None
     if connection.vendor == 'postgresql':
         return super().get_db_prep_save(value, connection)
     else:
         if isinstance(value, str):  # we need to convert it to the non-postgres format
             return relativedelta_as_csv(parse_relativedelta(value))
         return relativedelta_as_csv(value)
Ejemplo n.º 2
0
 def get_db_prep_value(self, value, connection, prepared=False):
     if value is None:
         return value
     else:
         if connection.vendor == 'postgresql':
             return format_relativedelta(self.to_python(value))
         else:
             return relativedelta_as_csv(self.to_python(value))
Ejemplo n.º 3
0
 def test_csv_conversions(self):
     self.assertEqual(
         relativedelta_as_csv(relativedelta(years=1925, months=9, days=-4,
                                            hours=-12, minutes=27, seconds=54,
                                            microseconds=-123456)),
         '01925/009/-04 -12:027:054.-123456')
     self.assertEqual(
         parse_relativedelta('01925/009/-04 -12:027:054.-123456'),
         relativedelta(years=1925, months=9, days=-4,
                       hours=-12, minutes=27, seconds=54,
                       microseconds=-123456)
     )
     self.assertEqual(
         relativedelta_as_csv(relativedelta(years=-1925, months=9, days=-4,
                                            hours=-12, minutes=27, seconds=-54,
                                            microseconds=123456)),
         '-1925/009/-04 -12:027:-54.0123456')
     self.assertEqual(
         parse_relativedelta('-1925/009/-04 -12:027:-54.0123456'),
         relativedelta(years=-1925, months=9, days=-4,
                       hours=-12, minutes=27, seconds=-54,
                       microseconds=123456)
     )