j2labs/dictshield — pull request #47 by alexanderdean (2011-12-04 22:25:54+00:00)
Title: New format constructor argument for DateTimeField

Problem: there aren't many APIs out there which expect JSON dates to be formatted in the Python `isoformat()` format currently output by DictShield.

To work around this I've added a new `format` argument to `DateTimeField`, which can take either a string (which is a `strftime` [format](http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior)) or a custom function/lambda to output a formatted date.

Example usages:

ordered_at = DateTimeField(format="%Y-%m-%dT%H:%M:%S%z")

Or:

date_formatter = lambda dt : dt.strftime("%Y%m%dT%H:%M:%S.%f")[:-3] # Truncate micro- to milliseconds
last_updated = DateTimeField(format=date_formatter, required=True)