comparison backend/couchdb/ListDateTimeField.py @ 170:f0afcd1c5656

implement a couchdb mapping field that stores a datetime instance as a JSON array
author dirk
date Fri, 09 Sep 2011 16:22:44 +0200
parents
children bb3c851b18b1
comparison
equal deleted inserted replaced
169:91a24f499318 170:f0afcd1c5656
1
2 from couchdb.mapping import Field
3 from datetime import datetime
4
5 class ListDateTimeField(Field):
6 def _to_python(self, value):
7 if isinstance(value, list):
8 return datetime(*value)
9 return value
10
11 def _to_json(self, value):
12 if isinstance(value, datetime):
13 return [ value.year, value.month, value.day, value.hour, value.minute, value.second ]
14 return value