Hello, I have implemeted a TimestampField that maps betweem unixtimestamps and datetime.datetime objects, so i can use Datetime in Django while not having to convert all timestamps to datetime fields yet. I need that for downwards compatibility for an old application that uses the same database. The Plan is to use it until I can reimplement the old application in django and afterwards switch to Datetime and DateFields entirely.
from django.db.models.fields import DateTimeField, IntegerField, Field from datetime import datetime from time import mktime class TimestampField(DateTimeField): def get_internal_type(self): return "IntegerField" def _get_val_from_obj(self, obj): try: return datetime.fromtimestamp((getattr(obj, self.attname))) except: return datetime.fromtimestamp(0) def get_db_prep_save(self, value): if type(value) is datetime: value = int(mktime(value.timetuple())) else: value = int(value) return Field.get_db_prep_save(self, value) Can someone comment wether this is a "proper" approach or wether I'll perhaps experience other problems with this solution? Regards --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---