Skip to main content

UnixDateTimeField in Django

Project description

https://travis-ci.org/Niklas9/django-unixdatetimefield.svg?branch=master Latest Version Downloads

Provides a UnixDateTimeField for your Django models.

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 (or easy_install):

pip install django-unixdatetimefield

License

BSD, just as the main Django project. See LICENSE file in root of this repo.

Contributing

This project accepts contributions via GitHub pull requests.

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-0.1.4.tar.gz (3.8 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for django-unixdatetimefield-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ed4a4c8c9cc28884931427e3487d796b68f16a2f60ce54c429d2b566890aeea7
MD5 050c89d5cf89f4b8201fcc77053d62de
BLAKE2b-256 fcbfcb005f3a397ad710d22f0a3668d8ef31a1d3095e3155b07b9ea68d921b7c

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