On Tue, Feb 1, 2011 at 1:24 PM, Oleg Broytman <ph...@ph...> wrote:
> On Tue, Feb 01, 2011 at 09:13:35PM +0300, Oleg Broytman wrote:
>> def DateTimeConverter(value, db):
>> return "'%s'" % value.isoformat
>
> Oops, sorry, a bug:
>
> return "'%s'" % value.isoformat()
>
>>
>> registerConverter(datetime.datetime, DateTimeConverter)
Thank you as always Oleg for your prompt reply.
I will give this a try, meanwhile I have created my own column type:
--
class ISO8601Validator(validators.Validator):
def from_python(self, value, state):
if value is not None:
value = value.strftime('%Y-%m-%d %H:%M:%S.%f')
return value
def to_python(self, value, state):
if value is not None:
value = datetime.datetime.strptime(value, '%Y-%m-%d %H:%M:%S.%f')
return value
class SOISO8601Col(SOStringCol):
def createValidators(self):
return [ISO8601Validator()] + \
super(SOISO8601Col, self).createValidators()
class ISO8601Col(StringCol):
baseClass = SOISO8601Col
--
This seems to work for me. Will registering a converter work both
ways? i.e. the value is transformed to string for storage and back
again for retrieval?
|