I have a MySQL database, right now I\'m generating all of the datetime fields as models.DateTimeField. Is there a way to get a timestamp instead? I
The pip package django-unixdatetimefield provides a UnixDateTimeField field that you can use for this out of the box (https://pypi.python.org/pypi/django-unixdatetimefield/).
Example model:
from django_unixdatetimefield import UnixDateTimeField
class MyModel(models.Model):
created_at = UnixDateTimeField()
Python ORM query:
>>> m = MyModel()
>>> m.created_at = datetime.datetime(2015, 2, 21, 19, 38, 32, 209148)
>>> m.save()
Database:
sqlite> select created_at from mymodel;
1426967129
Here's the source code if interested - https://github.com/Niklas9/django-unixdatetimefield.
Disclaimer: I'm the author of this pip package.