I'm trying to make a fork of MongoEngine that will allow auto updating of a DateTimeField
based on passing True to an auto_now
or auto_now_add
(a la Django).
So far I've added the attributes to the __init__
method of DateTimeField
like so:
def __init__(self, auto_now=None, auto_now_add=None, **kwargs):
self.auto_now, self.auto_now_add = auto_now, auto_now_add
super(DateTimeField, self).__init__(**kwargs)
Unfortunately, I cannot figure out how to populate this value cleanly when a document is created/saved. The only solution I see so far, is to add field specific behavior in BaseDocument's save or validate methods... But I don't like it.
Does anyone know of a better method?
By the way: I though of having a go at this after reading this question and @equinoxel's comment about extending mongo and being used to this attribute in django.