Package: django-unixtimestampfield
Provide a custom field that is stored as float (UTC POSIX timestamp) and used as datetime instance.Requirements and CompatibilityDatabase that supportsFloattype is compatible.Currently tested with metrics:Django/Python3.53.63.73.82.2.xvvv3.0.xvvvNote: for Python2 and Django1.X, please use v0.3.9 or previous version.Installpipinstalldjango-unixtimestampfieldUsageUsed in model as following:fromdjango.dbimportmodelsfromunixtimestampfield.fieldsimportUnixTimeStampFieldclassModelA(models.Model):created=UnixTimeStampField(auto_now_add=True)modified=UnixTimeStampField(auto_now=True)str_ini=UnixTimeStampField(default='0.0')float_ini=UnixTimeStampField(default=0.0)int_ini=UnixTimeStampField(default=0.0)dt_ini=UnixTimeStampField(default=timezone.now)num_field=UnixTimeStampField(use_numeric=True,default=0.0)Operation exmpale:>>>m=modelA.objects.create()>>>m.createddatetime.datetime(2015,9,2,10,41,41,937257,tzinfo=<UTC>)>>>m.int_inidatetime.datetime(1970,1,1,0,0,tzinfo=<UTC>)>>>m.int_ini=3>>>m.save()>>>m.int_inidatetime.datetime(1970,1,1,0,3,tzinfo=<UTC>)>>>m.num_field0.0Field Optionsauto_now: Set to True for updating while saving, just like DatetimeFieldauto_now_add: set to True for updating while creating, just like DatetimeFieldround_to: percision (num)  of round(value,num), default:6use_float:DEPRECATED in v0.3, see use_numericuse_numeric: set as True that instance attribute would be numeric, default asFalseDjango settingsIfUSE_TZis set toFalse, return current datetime (in UTC timezone) info withouttzinfowhile accessing attribute.Example:# In settings.pyUSE_TZ=False>>>m=modelA.objects.create()>>>m.createddatetime.datetime(2015,9,2,10,41,41,937257)Template TagsLoad template tags:{% load unixtimestampfield %}Two django template filter tags are available:to_datetime: Filter value as datetimeto_timestamp: Filter value as timestampTricky Sub-middlewareDue to value is stored as float, it’s hard for recognizing and leads to this tricky middleware.Here are 3 modes to show data:usf_default: Show data by default, according to use_numeric option of field. This is also default setting.usf_datetime: Always convert to datetime objectusf_timestamp: Always convert to timestampUseUSF_FORMATto indicate display police insettings.py. Let’s see examples.Assume ModelB as:classModelB(models.Model):num_field=UnixTimeStampField(use_numeric=True,default=0.0)dt_field=UnixTimeStampField(default=0.0)Then getting field value what you want:>>>m=ModelB()# with USF_FORMAT='usf_default' in settings.py>>>m.num_field,m.dt_field(0.0,datetime.datetime(1970,1,1,0,0))# with USF_FORMAT='usf_datetime' in settings.py>>>m.num_field,m.dt_field(datetime.datetime(1970,1,1,0,0),datetime.datetime(1970,1,1,0,0))# with USF_FORMAT='usf_timestamp' in settings.py>>>m.num_field,m.dt_field(0.0,0.0)Versionv0.4.0– Fix Python and Django compatiblity, check related sectionv0.3.9– Fix packages including in setup.pyv0.3.8– Bugs fixed: Apply submiddleware to auto_now field and check format in submiddlewareV0.3.7– Check minimum value.V0.3.6– Fix timezone problem. All records are stored UTC timezone and convert while retrive.V0.3.5.1– Integer compatibility and fix timezone problemV0.3.5– Parse time format: YYYY-mm-dd HH:MM:SS[.FFFFFF]V0.3.4– Bugs fixed.V0.3.3– Add sub-middleware and template tagsv0.3– Add ordinal time field and change field optionsuse_floattouse_numeric!!!v0.2– Handle formfield and add options while initv0.1– Added UnixTimeStampFieldLICENSEMIT