Skip to content

Instantly share code, notes, and snippets.

View klenwell's full-sized avatar

klenwell klenwell

View GitHub Profile
@chrisfarms
chrisfarms / basemodel.py
Created March 22, 2011 19:50
GAE base model class with to_json serialisation
SIMPLE_TYPES = (int, long, float, bool, dict, basestring, list)
class BaseModel(db.Model):
def to_json_friendly_value(self, v):
if v is None or isinstance(v, SIMPLE_TYPES):
value = v
elif isinstance(v, datetime.date):
# Convert date/datetime to ms-since-epoch ("new Date()").
ms = time.mktime(v.utctimetuple()) * 1000