
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
django-unixdatetimefield
Advanced tools
Provides a UnixDateTimeField for your Django models. Now with Django 3 support as well.
I have found this especially useful when integrating Django into legacy databases, where the typical DateTime column type is rather stored as a Unix timestamp (http://en.wikipedia.org/wiki/Unix_time).
UnixDateTimeField is based on the implementation of the standard Django DateTimeField, making it 100% compatible with all features and options it supports.
First you'll need to attach a UnixDateTimeField to your model. This acts as a the equivalence of a Django PositiveIntegerField at the database level but provides a Django DateTimeField at the ORM abstraction layer.
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
Enjoy!
Install with pip:
pip install django-unixdatetimefield
Current support matrix (routinely tested for for each release, see .travis.yml
for more details):
As the main use-case of this library is to integrate with legacy databases -- I'm keen to keep older versions of Python and Django supported. Let me know if you're using a combination that's not supported, and I'll be happy to try to see if we can support it.
I acknowledge though, and respect, the ones who prefer using unix timestamps in their databases, but in my experience those devs are increasingly becoming fewer and fewer :)
This project accepts contributions via GitHub pull requests.
The easiest way I've found to test the different mixes of Python and Django
versions has been to use Docker, with simple flags to boot up with e.g. Python 2.7
or 3.8, and e.g. Django 1.11.x or Django 3.x. For anyone who wants to test or contribute, I believe this is the fastest way.
There's a helperfile named build_n_run.sh
that will build the docker image and spin up a container automatically.
In general, I think this guide is pretty useful -- https://www.digitalocean.com/community/tutorials/how-to-package-and-distribute-python-applications. As all settings are setup in this project already, it should simply be to
$ python3 setup.py sdist
$ python3 setup.py sdist upload
remember to update the verion numbers in setup.py
and django_unixdatetimefield/__init__.py
beforehand.
BSD, just as the main Django project. Please see LICENSE
file in root of this repo.
FAQs
UnixDateTimeField in Django
We found that django-unixdatetimefield demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.