Skip to main content

UnixDateTimeField in Django

Project description

# django-unixdatetimefield

[![Build Status](https://travis-ci.org/Niklas9/django-unixdatetimefield.svg?branch=master)](https://travis-ci.org/Niklas9/django-unixdatetimefield) [![Latest Version](https://img.shields.io/pypi/v/django-unixdatetimefield.svg?style=flat) ](https://pypi.python.org/pypi/django-unixdatetimefield/) [![Downloads](https://pepy.tech/badge/django-unixdatetimefield/week)](https://pepy.tech/project/django-unixdatetimefield)

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.

## Usage

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!

## Installation

Install with pip:

pip install django-unixdatetimefield

## Compatibility Current support matrix (routinely tested for for each release, see .travis.yml for more details):

  • Django 1.11.x with Python 2.7, 3.4, 3.5

  • Django 2.0.x with Python 3.4

  • Django 2.x.y with Python 3.5

  • Django 2-3.x with Python 3.6, 3.7, 3.8

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 :)

## Contributing This project accepts contributions via GitHub pull requests.

### Testing 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.

### Uploading to pypi 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

  1. $ python3 setup.py sdist

  2. $ python3 setup.py sdist upload

remember to update the verion numbers in setup.py and django_unixdatetimefield/__init__.py beforehand.

## License BSD, just as the main Django project. Please see LICENSE file in root of this repo.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-unixdatetimefield-1.2.0.tar.gz (5.6 kB view details)

Uploaded Source

File details

Details for the file django-unixdatetimefield-1.2.0.tar.gz.

File metadata

File hashes

Hashes for django-unixdatetimefield-1.2.0.tar.gz
Algorithm Hash digest
SHA256 809614c3b65caf3f0cbb40ec3d5efab13ccd01c556e00426dc01b67f03fcbf9d
MD5 237cebd7ce7000758c799308450ff96b
BLAKE2b-256 01ee32e190c03c9514141bd2b25e316a6f2bf262241b42660a1cc7529f48ed61

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page